{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Action1资金流入流出预测    \n",
    "https://tianchi.aliyun.com/competition/entrance/231573/information     \n",
    "数据集一共包括4张表：用户基本信息数据、用户申购赎回数据、收益率表和银行间拆借利率表    \n",
    "2.8万用户，284万行为数据，294天拆解利率，427天收益率     \n",
    "2013-07-01到2014-08-31，预测2014年9月的申购和赎回"
   ]
  },
  {
   "attachments": {
    "09d9c0c2-4873-4f86-8958-74695d253b29.png": {
     "image/png": "iVBORw0KGgoAAAANSUhEUgAAAcYAAAB3CAYAAACZg+BNAAAgAElEQVR4Ae2d70scybrHzx91wPNmXgxkFQ7Ji92wBAxCcokQGDigsCjsQQgYFo4EMjegHDAkIAkEFwYPDAgJG3ZJiEQYcEgI+mKTQDRsGEEcrvfOuV6eS3X3U/1UdVV1jzNqdL6C9K/6+amnnm9XdXXPnwh/IAACIAACIAACmsCf9B52QAAEQAAEQAAECMIIIwABEAABEAABQQDCKGBgFwRAAARAAAQgjLABEAABEAABEBAEIIwCBnZBAARAAARAAMIIGwABEAABEAABQQDCKGBgFwRAAARAAAQgjLABEAABEAABEBAEIIwCBnZBAARAAARAAMIIGwABEAABEAABQQDCKGBgFwRAAARAAAQgjLABEAABEAABEBAEIIwCBnZBAARAAARAAMIIGwABEAABEAABQQDCKGBgFwRAAARAAAQgjLABEAABEAABEBAEIIwCBnZBAARAAARAAMIIGwABEAABEAABQQDCKGBgFwRAAARAAAQgjLABEAABEAABEBAEIIwCBnZBAARAAARAAMIIGwABEAABEAABQQDCKGBgFwRAAARAAAQgjLABEAABEAABEBAEIIwCBnZBAARAAARAAMIIGwABEAABEAABQaCvwvh/f3ym//7nf1L7P67Q3jd/ob3yn6OtOlbn1XX8gQAIgAAIgMDXTKBvwtip11IxVILo+v/mL6TC4Q8EQAAEQAAEvlYCfRHGSBQTIfyv2b/T/240iP7diev87050rM6zWEIcv1ZzQLlAAARAAAR6FkY1PcrTpv/zZClIVF3n6VVMqwZR4SIIgAAIgMApEehZGNWzQyV2akRY5I9Hjioe/kAABEAABEDgayPQszBGC23Kf46nTwvUTk2zKiFV8fAHAiAAAiAAAl8bgZ6FkadR9TPFvBr+u6OnU/OC4joIgAAIgAAInDSB3oUxWXTTTcF5EU43cU4vbJuatSotLKr/J9Rsi5K0G7Qcna/SQq1B++ISdkEABM4pAdnvF5/RtqOarV9maGx8NP5//DYOsVun23xu/D41HfFCpzobC1Th+D/O0nJjNxQc13og0LswJu8rntqIsbNDzddrtN6X/y2HuO3Qyg9lGiqp/wqtfBG0v9RoIjpfpqEfatSKLr2lR2y83u0MPYdNC5DYBYEzRED2+1LV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"
    }
   },
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![image.png](attachment:09d9c0c2-4873-4f86-8958-74695d253b29.png)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>user_id</th>\n",
       "      <th>report_date</th>\n",
       "      <th>tBalance</th>\n",
       "      <th>yBalance</th>\n",
       "      <th>total_purchase_amt</th>\n",
       "      <th>direct_purchase_amt</th>\n",
       "      <th>purchase_bal_amt</th>\n",
       "      <th>purchase_bank_amt</th>\n",
       "      <th>total_redeem_amt</th>\n",
       "      <th>consume_amt</th>\n",
       "      <th>transfer_amt</th>\n",
       "      <th>tftobal_amt</th>\n",
       "      <th>tftocard_amt</th>\n",
       "      <th>share_amt</th>\n",
       "      <th>category1</th>\n",
       "      <th>category2</th>\n",
       "      <th>category3</th>\n",
       "      <th>category4</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>20140805</td>\n",
       "      <td>20385</td>\n",
       "      <td>20383</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>20140808</td>\n",
       "      <td>20391</td>\n",
       "      <td>20389</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>20140811</td>\n",
       "      <td>20397</td>\n",
       "      <td>20395</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>20140814</td>\n",
       "      <td>20403</td>\n",
       "      <td>20401</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1</td>\n",
       "      <td>20140817</td>\n",
       "      <td>20409</td>\n",
       "      <td>20407</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2840416</th>\n",
       "      <td>28033</td>\n",
       "      <td>20140825</td>\n",
       "      <td>550646</td>\n",
       "      <td>550585</td>\n",
       "      <td>61</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>61</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2840417</th>\n",
       "      <td>28033</td>\n",
       "      <td>20140831</td>\n",
       "      <td>525707</td>\n",
       "      <td>538147</td>\n",
       "      <td>60</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>12500</td>\n",
       "      <td>12500</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>60</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>12500.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2840418</th>\n",
       "      <td>28033</td>\n",
       "      <td>20140724</td>\n",
       "      <td>20487121</td>\n",
       "      <td>20484824</td>\n",
       "      <td>2297</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2297</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2840419</th>\n",
       "      <td>28033</td>\n",
       "      <td>20140727</td>\n",
       "      <td>20462288</td>\n",
       "      <td>20491722</td>\n",
       "      <td>2298</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>31732</td>\n",
       "      <td>0</td>\n",
       "      <td>31732</td>\n",
       "      <td>0</td>\n",
       "      <td>31732</td>\n",
       "      <td>2298</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2840420</th>\n",
       "      <td>28035</td>\n",
       "      <td>20140305</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>2840421 rows × 18 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "         user_id  report_date  tBalance  yBalance  total_purchase_amt  \\\n",
       "0              1     20140805     20385     20383                   2   \n",
       "1              1     20140808     20391     20389                   2   \n",
       "2              1     20140811     20397     20395                   2   \n",
       "3              1     20140814     20403     20401                   2   \n",
       "4              1     20140817     20409     20407                   2   \n",
       "...          ...          ...       ...       ...                 ...   \n",
       "2840416    28033     20140825    550646    550585                  61   \n",
       "2840417    28033     20140831    525707    538147                  60   \n",
       "2840418    28033     20140724  20487121  20484824                2297   \n",
       "2840419    28033     20140727  20462288  20491722                2298   \n",
       "2840420    28035     20140305         0         0                   0   \n",
       "\n",
       "         direct_purchase_amt  purchase_bal_amt  purchase_bank_amt  \\\n",
       "0                          0                 0                  0   \n",
       "1                          0                 0                  0   \n",
       "2                          0                 0                  0   \n",
       "3                          0                 0                  0   \n",
       "4                          0                 0                  0   \n",
       "...                      ...               ...                ...   \n",
       "2840416                    0                 0                  0   \n",
       "2840417                    0                 0                  0   \n",
       "2840418                    0                 0                  0   \n",
       "2840419                    0                 0                  0   \n",
       "2840420                    0                 0                  0   \n",
       "\n",
       "         total_redeem_amt  consume_amt  transfer_amt  tftobal_amt  \\\n",
       "0                       0            0             0            0   \n",
       "1                       0            0             0            0   \n",
       "2                       0            0             0            0   \n",
       "3                       0            0             0            0   \n",
       "4                       0            0             0            0   \n",
       "...                   ...          ...           ...          ...   \n",
       "2840416                 0            0             0            0   \n",
       "2840417             12500        12500             0            0   \n",
       "2840418                 0            0             0            0   \n",
       "2840419             31732            0         31732            0   \n",
       "2840420                 0            0             0            0   \n",
       "\n",
       "         tftocard_amt  share_amt  category1  category2  category3  category4  \n",
       "0                   0          2        NaN        NaN        NaN        NaN  \n",
       "1                   0          2        NaN        NaN        NaN        NaN  \n",
       "2                   0          2        NaN        NaN        NaN        NaN  \n",
       "3                   0          2        NaN        NaN        NaN        NaN  \n",
       "4                   0          2        NaN        NaN        NaN        NaN  \n",
       "...               ...        ...        ...        ...        ...        ...  \n",
       "2840416             0         61        NaN        NaN        NaN        NaN  \n",
       "2840417             0         60        0.0        0.0        0.0    12500.0  \n",
       "2840418             0       2297        NaN        NaN        NaN        NaN  \n",
       "2840419         31732       2298        NaN        NaN        NaN        NaN  \n",
       "2840420             0          0        NaN        NaN        NaN        NaN  \n",
       "\n",
       "[2840421 rows x 18 columns]"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "# 数据加载\n",
    "data = pd.read_csv('user_balance_table.csv')\n",
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>user_id</th>\n",
       "      <th>report_date</th>\n",
       "      <th>tBalance</th>\n",
       "      <th>yBalance</th>\n",
       "      <th>total_purchase_amt</th>\n",
       "      <th>direct_purchase_amt</th>\n",
       "      <th>purchase_bal_amt</th>\n",
       "      <th>purchase_bank_amt</th>\n",
       "      <th>total_redeem_amt</th>\n",
       "      <th>consume_amt</th>\n",
       "      <th>...</th>\n",
       "      <th>share_amt</th>\n",
       "      <th>category1</th>\n",
       "      <th>category2</th>\n",
       "      <th>category3</th>\n",
       "      <th>category4</th>\n",
       "      <th>day</th>\n",
       "      <th>month</th>\n",
       "      <th>year</th>\n",
       "      <th>week</th>\n",
       "      <th>weekday</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>2014-08-05</td>\n",
       "      <td>20385</td>\n",
       "      <td>20383</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>2</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>5</td>\n",
       "      <td>8</td>\n",
       "      <td>2014</td>\n",
       "      <td>32</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>2014-08-08</td>\n",
       "      <td>20391</td>\n",
       "      <td>20389</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>2</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>8</td>\n",
       "      <td>8</td>\n",
       "      <td>2014</td>\n",
       "      <td>32</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>2014-08-11</td>\n",
       "      <td>20397</td>\n",
       "      <td>20395</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>2</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>11</td>\n",
       "      <td>8</td>\n",
       "      <td>2014</td>\n",
       "      <td>33</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>2014-08-14</td>\n",
       "      <td>20403</td>\n",
       "      <td>20401</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>2</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>14</td>\n",
       "      <td>8</td>\n",
       "      <td>2014</td>\n",
       "      <td>33</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1</td>\n",
       "      <td>2014-08-17</td>\n",
       "      <td>20409</td>\n",
       "      <td>20407</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>2</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>17</td>\n",
       "      <td>8</td>\n",
       "      <td>2014</td>\n",
       "      <td>33</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2840416</th>\n",
       "      <td>28033</td>\n",
       "      <td>2014-08-25</td>\n",
       "      <td>550646</td>\n",
       "      <td>550585</td>\n",
       "      <td>61</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>61</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>25</td>\n",
       "      <td>8</td>\n",
       "      <td>2014</td>\n",
       "      <td>35</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2840417</th>\n",
       "      <td>28033</td>\n",
       "      <td>2014-08-31</td>\n",
       "      <td>525707</td>\n",
       "      <td>538147</td>\n",
       "      <td>60</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>12500</td>\n",
       "      <td>12500</td>\n",
       "      <td>...</td>\n",
       "      <td>60</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>12500.0</td>\n",
       "      <td>31</td>\n",
       "      <td>8</td>\n",
       "      <td>2014</td>\n",
       "      <td>35</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2840418</th>\n",
       "      <td>28033</td>\n",
       "      <td>2014-07-24</td>\n",
       "      <td>20487121</td>\n",
       "      <td>20484824</td>\n",
       "      <td>2297</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>2297</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>24</td>\n",
       "      <td>7</td>\n",
       "      <td>2014</td>\n",
       "      <td>30</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2840419</th>\n",
       "      <td>28033</td>\n",
       "      <td>2014-07-27</td>\n",
       "      <td>20462288</td>\n",
       "      <td>20491722</td>\n",
       "      <td>2298</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>31732</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>2298</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>27</td>\n",
       "      <td>7</td>\n",
       "      <td>2014</td>\n",
       "      <td>30</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2840420</th>\n",
       "      <td>28035</td>\n",
       "      <td>2014-03-05</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>5</td>\n",
       "      <td>3</td>\n",
       "      <td>2014</td>\n",
       "      <td>10</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>2840421 rows × 23 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "         user_id report_date  tBalance  yBalance  total_purchase_amt  \\\n",
       "0              1  2014-08-05     20385     20383                   2   \n",
       "1              1  2014-08-08     20391     20389                   2   \n",
       "2              1  2014-08-11     20397     20395                   2   \n",
       "3              1  2014-08-14     20403     20401                   2   \n",
       "4              1  2014-08-17     20409     20407                   2   \n",
       "...          ...         ...       ...       ...                 ...   \n",
       "2840416    28033  2014-08-25    550646    550585                  61   \n",
       "2840417    28033  2014-08-31    525707    538147                  60   \n",
       "2840418    28033  2014-07-24  20487121  20484824                2297   \n",
       "2840419    28033  2014-07-27  20462288  20491722                2298   \n",
       "2840420    28035  2014-03-05         0         0                   0   \n",
       "\n",
       "         direct_purchase_amt  purchase_bal_amt  purchase_bank_amt  \\\n",
       "0                          0                 0                  0   \n",
       "1                          0                 0                  0   \n",
       "2                          0                 0                  0   \n",
       "3                          0                 0                  0   \n",
       "4                          0                 0                  0   \n",
       "...                      ...               ...                ...   \n",
       "2840416                    0                 0                  0   \n",
       "2840417                    0                 0                  0   \n",
       "2840418                    0                 0                  0   \n",
       "2840419                    0                 0                  0   \n",
       "2840420                    0                 0                  0   \n",
       "\n",
       "         total_redeem_amt  consume_amt  ...  share_amt  category1  category2  \\\n",
       "0                       0            0  ...          2        NaN        NaN   \n",
       "1                       0            0  ...          2        NaN        NaN   \n",
       "2                       0            0  ...          2        NaN        NaN   \n",
       "3                       0            0  ...          2        NaN        NaN   \n",
       "4                       0            0  ...          2        NaN        NaN   \n",
       "...                   ...          ...  ...        ...        ...        ...   \n",
       "2840416                 0            0  ...         61        NaN        NaN   \n",
       "2840417             12500        12500  ...         60        0.0        0.0   \n",
       "2840418                 0            0  ...       2297        NaN        NaN   \n",
       "2840419             31732            0  ...       2298        NaN        NaN   \n",
       "2840420                 0            0  ...          0        NaN        NaN   \n",
       "\n",
       "         category3  category4  day  month  year  week  weekday  \n",
       "0              NaN        NaN    5      8  2014    32        1  \n",
       "1              NaN        NaN    8      8  2014    32        4  \n",
       "2              NaN        NaN   11      8  2014    33        0  \n",
       "3              NaN        NaN   14      8  2014    33        3  \n",
       "4              NaN        NaN   17      8  2014    33        6  \n",
       "...            ...        ...  ...    ...   ...   ...      ...  \n",
       "2840416        NaN        NaN   25      8  2014    35        0  \n",
       "2840417        0.0    12500.0   31      8  2014    35        6  \n",
       "2840418        NaN        NaN   24      7  2014    30        3  \n",
       "2840419        NaN        NaN   27      7  2014    30        6  \n",
       "2840420        NaN        NaN    5      3  2014    10        2  \n",
       "\n",
       "[2840421 rows x 23 columns]"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 给数据添加事件维度\n",
    "def add_timestamp(data):\n",
    "    # 事件格式转换\n",
    "    data['report_date'] = pd.to_datetime(data['report_date'], format='%Y%m%d')\n",
    "    # 添加时间维度\n",
    "    data['day'] = data['report_date'].dt.day\n",
    "    data['month'] = data['report_date'].dt.month\n",
    "    data['year'] = data['report_date'].dt.year\n",
    "    data['week'] = data['report_date'].dt.week # 在一年中的第多少个week\n",
    "    data['weekday'] = data['report_date'].dt.weekday # 0代表周一，6代表周日\n",
    "    return data\n",
    "data = add_timestamp(data)\n",
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "<ipython-input-3-cd32de933c13>:5: FutureWarning: Indexing with multiple keys (implicitly converted to a tuple of keys) will be deprecated, use a list instead.\n",
      "  df_temp = df_temp.groupby(['report_date'])['total_purchase_amt','total_redeem_amt'].sum()\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>report_date</th>\n",
       "      <th>total_purchase_amt</th>\n",
       "      <th>total_redeem_amt</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>243</th>\n",
       "      <td>2014-03-01</td>\n",
       "      <td>362865580</td>\n",
       "      <td>211279011</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>244</th>\n",
       "      <td>2014-03-02</td>\n",
       "      <td>276202230</td>\n",
       "      <td>246199417</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>245</th>\n",
       "      <td>2014-03-03</td>\n",
       "      <td>505305862</td>\n",
       "      <td>513017360</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>246</th>\n",
       "      <td>2014-03-04</td>\n",
       "      <td>524146340</td>\n",
       "      <td>250562978</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>247</th>\n",
       "      <td>2014-03-05</td>\n",
       "      <td>454295491</td>\n",
       "      <td>209072753</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>422</th>\n",
       "      <td>2014-08-27</td>\n",
       "      <td>302194801</td>\n",
       "      <td>468164147</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>423</th>\n",
       "      <td>2014-08-28</td>\n",
       "      <td>245082751</td>\n",
       "      <td>297893861</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>424</th>\n",
       "      <td>2014-08-29</td>\n",
       "      <td>267554713</td>\n",
       "      <td>273756380</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>425</th>\n",
       "      <td>2014-08-30</td>\n",
       "      <td>199708772</td>\n",
       "      <td>196374134</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>426</th>\n",
       "      <td>2014-08-31</td>\n",
       "      <td>275090213</td>\n",
       "      <td>292943033</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>184 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "    report_date  total_purchase_amt  total_redeem_amt\n",
       "243  2014-03-01           362865580         211279011\n",
       "244  2014-03-02           276202230         246199417\n",
       "245  2014-03-03           505305862         513017360\n",
       "246  2014-03-04           524146340         250562978\n",
       "247  2014-03-05           454295491         209072753\n",
       "..          ...                 ...               ...\n",
       "422  2014-08-27           302194801         468164147\n",
       "423  2014-08-28           245082751         297893861\n",
       "424  2014-08-29           267554713         273756380\n",
       "425  2014-08-30           199708772         196374134\n",
       "426  2014-08-31           275090213         292943033\n",
       "\n",
       "[184 rows x 3 columns]"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def get_total_balance(data, begin): # 筛选指定日期之后的数据\n",
    "    # 在copy数据上进行操作\n",
    "    df_temp = data.copy()\n",
    "    # 按照date进行聚合\n",
    "    df_temp = df_temp.groupby(['report_date'])['total_purchase_amt','total_redeem_amt'].sum()\n",
    "    # 欢迎date字段，重新索引\n",
    "    df_temp.reset_index(inplace=True)\n",
    "    df_temp= df_temp[df_temp['report_date'] >= begin]\n",
    "    return df_temp\n",
    "\n",
    "# 筛选从2014-04-01之后的数据 =》作为平稳数据\n",
    "total_balance = get_total_balance(data, '2014-03-01')\n",
    "total_balance"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>report_date</th>\n",
       "      <th>total_purchase_amt</th>\n",
       "      <th>total_redeem_amt</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>243</th>\n",
       "      <td>2014-03-01</td>\n",
       "      <td>362865580.0</td>\n",
       "      <td>211279011.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>244</th>\n",
       "      <td>2014-03-02</td>\n",
       "      <td>276202230.0</td>\n",
       "      <td>246199417.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>245</th>\n",
       "      <td>2014-03-03</td>\n",
       "      <td>505305862.0</td>\n",
       "      <td>513017360.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>246</th>\n",
       "      <td>2014-03-04</td>\n",
       "      <td>524146340.0</td>\n",
       "      <td>250562978.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>247</th>\n",
       "      <td>2014-03-05</td>\n",
       "      <td>454295491.0</td>\n",
       "      <td>209072753.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>2014-09-26</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>2014-09-27</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>2014-09-28</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>2014-09-29</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>2014-09-30</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>214 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "    report_date  total_purchase_amt  total_redeem_amt\n",
       "243  2014-03-01         362865580.0       211279011.0\n",
       "244  2014-03-02         276202230.0       246199417.0\n",
       "245  2014-03-03         505305862.0       513017360.0\n",
       "246  2014-03-04         524146340.0       250562978.0\n",
       "247  2014-03-05         454295491.0       209072753.0\n",
       "..          ...                 ...               ...\n",
       "25   2014-09-26                 NaN               NaN\n",
       "26   2014-09-27                 NaN               NaN\n",
       "27   2014-09-28                 NaN               NaN\n",
       "28   2014-09-29                 NaN               NaN\n",
       "29   2014-09-30                 NaN               NaN\n",
       "\n",
       "[214 rows x 3 columns]"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import datetime\n",
    "import numpy as np\n",
    "# 生成测试数据\n",
    "def generte_test_data(data):\n",
    "    total_balance = data.copy()\n",
    "    # 生成2014-09-01到2014-09-30的数据\n",
    "    start = datetime.datetime(2014,9,1)\n",
    "    end = datetime.datetime(2014,10,1)\n",
    "    testdata = []\n",
    "    while start != end:\n",
    "        # 添加3个字段：date, total_purchase_amt, total_redeem_amt\n",
    "        temp = [start, np.nan, np.nan]\n",
    "        testdata.append(temp)\n",
    "        # 日期加1\n",
    "        start += datetime.timedelta(days=1)\n",
    "    testdata = pd.DataFrame(testdata)\n",
    "    testdata.columns = total_balance.columns\n",
    "    # 将testdata合并到total_balance中\n",
    "    total_balance = pd.concat([total_balance, testdata],axis=0)\n",
    "    return total_balance\n",
    "total_balance = generte_test_data(total_balance)\n",
    "total_balance"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>report_date</th>\n",
       "      <th>total_purchase_amt</th>\n",
       "      <th>total_redeem_amt</th>\n",
       "      <th>day</th>\n",
       "      <th>month</th>\n",
       "      <th>year</th>\n",
       "      <th>week</th>\n",
       "      <th>weekday</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>243</th>\n",
       "      <td>2014-03-01</td>\n",
       "      <td>362865580.0</td>\n",
       "      <td>211279011.0</td>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>2014</td>\n",
       "      <td>9</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>244</th>\n",
       "      <td>2014-03-02</td>\n",
       "      <td>276202230.0</td>\n",
       "      <td>246199417.0</td>\n",
       "      <td>2</td>\n",
       "      <td>3</td>\n",
       "      <td>2014</td>\n",
       "      <td>9</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>245</th>\n",
       "      <td>2014-03-03</td>\n",
       "      <td>505305862.0</td>\n",
       "      <td>513017360.0</td>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "      <td>2014</td>\n",
       "      <td>10</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>246</th>\n",
       "      <td>2014-03-04</td>\n",
       "      <td>524146340.0</td>\n",
       "      <td>250562978.0</td>\n",
       "      <td>4</td>\n",
       "      <td>3</td>\n",
       "      <td>2014</td>\n",
       "      <td>10</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>247</th>\n",
       "      <td>2014-03-05</td>\n",
       "      <td>454295491.0</td>\n",
       "      <td>209072753.0</td>\n",
       "      <td>5</td>\n",
       "      <td>3</td>\n",
       "      <td>2014</td>\n",
       "      <td>10</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>2014-09-26</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>26</td>\n",
       "      <td>9</td>\n",
       "      <td>2014</td>\n",
       "      <td>39</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>2014-09-27</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>27</td>\n",
       "      <td>9</td>\n",
       "      <td>2014</td>\n",
       "      <td>39</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>2014-09-28</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>28</td>\n",
       "      <td>9</td>\n",
       "      <td>2014</td>\n",
       "      <td>39</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>2014-09-29</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>29</td>\n",
       "      <td>9</td>\n",
       "      <td>2014</td>\n",
       "      <td>40</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>2014-09-30</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>30</td>\n",
       "      <td>9</td>\n",
       "      <td>2014</td>\n",
       "      <td>40</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>214 rows × 8 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "    report_date  total_purchase_amt  total_redeem_amt  day  month  year  week  \\\n",
       "243  2014-03-01         362865580.0       211279011.0    1      3  2014     9   \n",
       "244  2014-03-02         276202230.0       246199417.0    2      3  2014     9   \n",
       "245  2014-03-03         505305862.0       513017360.0    3      3  2014    10   \n",
       "246  2014-03-04         524146340.0       250562978.0    4      3  2014    10   \n",
       "247  2014-03-05         454295491.0       209072753.0    5      3  2014    10   \n",
       "..          ...                 ...               ...  ...    ...   ...   ...   \n",
       "25   2014-09-26                 NaN               NaN   26      9  2014    39   \n",
       "26   2014-09-27                 NaN               NaN   27      9  2014    39   \n",
       "27   2014-09-28                 NaN               NaN   28      9  2014    39   \n",
       "28   2014-09-29                 NaN               NaN   29      9  2014    40   \n",
       "29   2014-09-30                 NaN               NaN   30      9  2014    40   \n",
       "\n",
       "     weekday  \n",
       "243        5  \n",
       "244        6  \n",
       "245        0  \n",
       "246        1  \n",
       "247        2  \n",
       "..       ...  \n",
       "25         4  \n",
       "26         5  \n",
       "27         6  \n",
       "28         0  \n",
       "29         1  \n",
       "\n",
       "[214 rows x 8 columns]"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 对total_balance 添加时间维度\n",
    "total_balance = add_timestamp(total_balance)\n",
    "total_balance"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 存储备份\n",
    "temp = total_balance.copy()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>weekday</th>\n",
       "      <th>purchase_weekday</th>\n",
       "      <th>redeem_weekday</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>3.273693e+08</td>\n",
       "      <td>3.456808e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>3.340518e+08</td>\n",
       "      <td>3.221266e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2</td>\n",
       "      <td>3.213877e+08</td>\n",
       "      <td>3.181960e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3</td>\n",
       "      <td>3.146910e+08</td>\n",
       "      <td>2.821480e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4</td>\n",
       "      <td>2.492893e+08</td>\n",
       "      <td>2.680463e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>5</td>\n",
       "      <td>1.958666e+08</td>\n",
       "      <td>1.840544e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>6</td>\n",
       "      <td>1.966477e+08</td>\n",
       "      <td>2.093138e+08</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   weekday  purchase_weekday  redeem_weekday\n",
       "0        0      3.273693e+08    3.456808e+08\n",
       "1        1      3.340518e+08    3.221266e+08\n",
       "2        2      3.213877e+08    3.181960e+08\n",
       "3        3      3.146910e+08    2.821480e+08\n",
       "4        4      2.492893e+08    2.680463e+08\n",
       "5        5      1.958666e+08    1.840544e+08\n",
       "6        6      1.966477e+08    2.093138e+08"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 就算total_balance发生改变\n",
    "total_balance = temp.copy()\n",
    "# total_balance = total_balance[['report_date','total_purchase_amt','total_redeem_amt']]\n",
    "weekday_weight = total_balance[['weekday','total_purchase_amt','total_redeem_amt']].groupby('weekday', as_index=False).mean()\n",
    "weekday_weight = weekday_weight.rename(columns={'total_purchase_amt':'purchase_weekday','total_redeem_amt':'redeem_weekday'})\n",
    "weekday_weight"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>weekday</th>\n",
       "      <th>purchase_weekday</th>\n",
       "      <th>redeem_weekday</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>1.185411</td>\n",
       "      <td>1.257964</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>1.209608</td>\n",
       "      <td>1.172248</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2</td>\n",
       "      <td>1.163752</td>\n",
       "      <td>1.157944</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3</td>\n",
       "      <td>1.139503</td>\n",
       "      <td>1.026762</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4</td>\n",
       "      <td>0.902682</td>\n",
       "      <td>0.975445</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>5</td>\n",
       "      <td>0.709237</td>\n",
       "      <td>0.669791</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>6</td>\n",
       "      <td>0.712065</td>\n",
       "      <td>0.761712</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   weekday  purchase_weekday  redeem_weekday\n",
       "0        0          1.185411        1.257964\n",
       "1        1          1.209608        1.172248\n",
       "2        2          1.163752        1.157944\n",
       "3        3          1.139503        1.026762\n",
       "4        4          0.902682        0.975445\n",
       "5        5          0.709237        0.669791\n",
       "6        6          0.712065        0.761712"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 周期因子\n",
    "weekday_weight['purchase_weekday'] /= np.mean(total_balance['total_purchase_amt'])\n",
    "weekday_weight['redeem_weekday'] /= np.mean(total_balance['total_redeem_amt'])\n",
    "weekday_weight"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>report_date</th>\n",
       "      <th>total_purchase_amt</th>\n",
       "      <th>total_redeem_amt</th>\n",
       "      <th>day</th>\n",
       "      <th>month</th>\n",
       "      <th>year</th>\n",
       "      <th>week</th>\n",
       "      <th>weekday</th>\n",
       "      <th>purchase_weekday</th>\n",
       "      <th>redeem_weekday</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2014-03-01</td>\n",
       "      <td>362865580.0</td>\n",
       "      <td>211279011.0</td>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>2014</td>\n",
       "      <td>9</td>\n",
       "      <td>5</td>\n",
       "      <td>0.709237</td>\n",
       "      <td>0.669791</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2014-03-02</td>\n",
       "      <td>276202230.0</td>\n",
       "      <td>246199417.0</td>\n",
       "      <td>2</td>\n",
       "      <td>3</td>\n",
       "      <td>2014</td>\n",
       "      <td>9</td>\n",
       "      <td>6</td>\n",
       "      <td>0.712065</td>\n",
       "      <td>0.761712</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2014-03-03</td>\n",
       "      <td>505305862.0</td>\n",
       "      <td>513017360.0</td>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "      <td>2014</td>\n",
       "      <td>10</td>\n",
       "      <td>0</td>\n",
       "      <td>1.185411</td>\n",
       "      <td>1.257964</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2014-03-04</td>\n",
       "      <td>524146340.0</td>\n",
       "      <td>250562978.0</td>\n",
       "      <td>4</td>\n",
       "      <td>3</td>\n",
       "      <td>2014</td>\n",
       "      <td>10</td>\n",
       "      <td>1</td>\n",
       "      <td>1.209608</td>\n",
       "      <td>1.172248</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2014-03-05</td>\n",
       "      <td>454295491.0</td>\n",
       "      <td>209072753.0</td>\n",
       "      <td>5</td>\n",
       "      <td>3</td>\n",
       "      <td>2014</td>\n",
       "      <td>10</td>\n",
       "      <td>2</td>\n",
       "      <td>1.163752</td>\n",
       "      <td>1.157944</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>209</th>\n",
       "      <td>2014-09-26</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>26</td>\n",
       "      <td>9</td>\n",
       "      <td>2014</td>\n",
       "      <td>39</td>\n",
       "      <td>4</td>\n",
       "      <td>0.902682</td>\n",
       "      <td>0.975445</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>210</th>\n",
       "      <td>2014-09-27</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>27</td>\n",
       "      <td>9</td>\n",
       "      <td>2014</td>\n",
       "      <td>39</td>\n",
       "      <td>5</td>\n",
       "      <td>0.709237</td>\n",
       "      <td>0.669791</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>211</th>\n",
       "      <td>2014-09-28</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>28</td>\n",
       "      <td>9</td>\n",
       "      <td>2014</td>\n",
       "      <td>39</td>\n",
       "      <td>6</td>\n",
       "      <td>0.712065</td>\n",
       "      <td>0.761712</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>212</th>\n",
       "      <td>2014-09-29</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>29</td>\n",
       "      <td>9</td>\n",
       "      <td>2014</td>\n",
       "      <td>40</td>\n",
       "      <td>0</td>\n",
       "      <td>1.185411</td>\n",
       "      <td>1.257964</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>213</th>\n",
       "      <td>2014-09-30</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>30</td>\n",
       "      <td>9</td>\n",
       "      <td>2014</td>\n",
       "      <td>40</td>\n",
       "      <td>1</td>\n",
       "      <td>1.209608</td>\n",
       "      <td>1.172248</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>214 rows × 10 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "    report_date  total_purchase_amt  total_redeem_amt  day  month  year  week  \\\n",
       "0    2014-03-01         362865580.0       211279011.0    1      3  2014     9   \n",
       "1    2014-03-02         276202230.0       246199417.0    2      3  2014     9   \n",
       "2    2014-03-03         505305862.0       513017360.0    3      3  2014    10   \n",
       "3    2014-03-04         524146340.0       250562978.0    4      3  2014    10   \n",
       "4    2014-03-05         454295491.0       209072753.0    5      3  2014    10   \n",
       "..          ...                 ...               ...  ...    ...   ...   ...   \n",
       "209  2014-09-26                 NaN               NaN   26      9  2014    39   \n",
       "210  2014-09-27                 NaN               NaN   27      9  2014    39   \n",
       "211  2014-09-28                 NaN               NaN   28      9  2014    39   \n",
       "212  2014-09-29                 NaN               NaN   29      9  2014    40   \n",
       "213  2014-09-30                 NaN               NaN   30      9  2014    40   \n",
       "\n",
       "     weekday  purchase_weekday  redeem_weekday  \n",
       "0          5          0.709237        0.669791  \n",
       "1          6          0.712065        0.761712  \n",
       "2          0          1.185411        1.257964  \n",
       "3          1          1.209608        1.172248  \n",
       "4          2          1.163752        1.157944  \n",
       "..       ...               ...             ...  \n",
       "209        4          0.902682        0.975445  \n",
       "210        5          0.709237        0.669791  \n",
       "211        6          0.712065        0.761712  \n",
       "212        0          1.185411        1.257964  \n",
       "213        1          1.209608        1.172248  \n",
       "\n",
       "[214 rows x 10 columns]"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "total_balance = pd.merge(total_balance, weekday_weight,on='weekday', how='left')\n",
    "total_balance"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>day</th>\n",
       "      <th>weekday</th>\n",
       "      <th>report_date</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1</td>\n",
       "      <td>5</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>179</th>\n",
       "      <td>30</td>\n",
       "      <td>6</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>180</th>\n",
       "      <td>31</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>181</th>\n",
       "      <td>31</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>182</th>\n",
       "      <td>31</td>\n",
       "      <td>5</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>183</th>\n",
       "      <td>31</td>\n",
       "      <td>6</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>184 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     day  weekday  report_date\n",
       "0      1        0            1\n",
       "1      1        1            2\n",
       "2      1        3            1\n",
       "3      1        4            1\n",
       "4      1        5            1\n",
       "..   ...      ...          ...\n",
       "179   30        6            1\n",
       "180   31        0            1\n",
       "181   31        3            1\n",
       "182   31        5            1\n",
       "183   31        6            1\n",
       "\n",
       "[184 rows x 3 columns]"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 计算日期因子\n",
    "# 统计周一到周日，在1-31日出现的频次['weekday','day']\n",
    "weekday_count = total_balance[['report_date','day','weekday']].groupby(['day','weekday'],as_index=False).count()\n",
    "weekday_count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>day</th>\n",
       "      <th>weekday</th>\n",
       "      <th>report_date</th>\n",
       "      <th>purchase_weekday</th>\n",
       "      <th>redeem_weekday</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1.185411</td>\n",
       "      <td>1.257964</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1.185411</td>\n",
       "      <td>1.257964</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1.185411</td>\n",
       "      <td>1.257964</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1.185411</td>\n",
       "      <td>1.257964</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1.185411</td>\n",
       "      <td>1.257964</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>179</th>\n",
       "      <td>25</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>1.163752</td>\n",
       "      <td>1.157944</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>180</th>\n",
       "      <td>26</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>1.163752</td>\n",
       "      <td>1.157944</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>181</th>\n",
       "      <td>27</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>1.163752</td>\n",
       "      <td>1.157944</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>182</th>\n",
       "      <td>28</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>1.163752</td>\n",
       "      <td>1.157944</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>183</th>\n",
       "      <td>30</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>1.163752</td>\n",
       "      <td>1.157944</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>184 rows × 5 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     day  weekday  report_date  purchase_weekday  redeem_weekday\n",
       "0      1        0            1          1.185411        1.257964\n",
       "1      2        0            1          1.185411        1.257964\n",
       "2      3        0            1          1.185411        1.257964\n",
       "3      4        0            1          1.185411        1.257964\n",
       "4      5        0            1          1.185411        1.257964\n",
       "..   ...      ...          ...               ...             ...\n",
       "179   25        2            1          1.163752        1.157944\n",
       "180   26        2            1          1.163752        1.157944\n",
       "181   27        2            1          1.163752        1.157944\n",
       "182   28        2            1          1.163752        1.157944\n",
       "183   30        2            2          1.163752        1.157944\n",
       "\n",
       "[184 rows x 5 columns]"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "weekday_count = pd.merge(weekday_count, weekday_weight,on='weekday')\n",
    "weekday_count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 日期计算= 周期因子*(周一到周日在1-31日中出现的频次)/一共有几个月\n",
    "weekday_count['purchase_weekday'] = weekday_count['purchase_weekday'] * weekday_count['report_date'] / len(np.unique(total_balance['month']))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([3, 4, 5, 6, 7, 8, 9], dtype=int64)"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.unique(total_balance['month'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "weekday_count['redeem_weekday'] = weekday_count['redeem_weekday'] * weekday_count['report_date'] / len(np.unique(total_balance['month']))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>day</th>\n",
       "      <th>purchase_weekday</th>\n",
       "      <th>redeem_weekday</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>1.009731</td>\n",
       "      <td>1.005167</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>1.006644</td>\n",
       "      <td>1.021864</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>1.037011</td>\n",
       "      <td>1.010455</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>1.030815</td>\n",
       "      <td>1.046789</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>1.002776</td>\n",
       "      <td>0.989992</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>6</td>\n",
       "      <td>0.935559</td>\n",
       "      <td>0.932230</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>7</td>\n",
       "      <td>0.999723</td>\n",
       "      <td>1.015369</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>8</td>\n",
       "      <td>1.009731</td>\n",
       "      <td>1.005167</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>9</td>\n",
       "      <td>1.006644</td>\n",
       "      <td>1.021864</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>10</td>\n",
       "      <td>1.037011</td>\n",
       "      <td>1.010455</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>11</td>\n",
       "      <td>1.030815</td>\n",
       "      <td>1.046789</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>12</td>\n",
       "      <td>1.002776</td>\n",
       "      <td>0.989992</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>13</td>\n",
       "      <td>0.935559</td>\n",
       "      <td>0.932230</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>14</td>\n",
       "      <td>0.999723</td>\n",
       "      <td>1.015369</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>15</td>\n",
       "      <td>1.009731</td>\n",
       "      <td>1.005167</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>16</td>\n",
       "      <td>1.006644</td>\n",
       "      <td>1.021864</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>17</td>\n",
       "      <td>1.037011</td>\n",
       "      <td>1.010455</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>18</td>\n",
       "      <td>1.030815</td>\n",
       "      <td>1.046789</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>19</td>\n",
       "      <td>1.002776</td>\n",
       "      <td>0.989992</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>20</td>\n",
       "      <td>0.935559</td>\n",
       "      <td>0.932230</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>21</td>\n",
       "      <td>0.999723</td>\n",
       "      <td>1.015369</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>22</td>\n",
       "      <td>1.009731</td>\n",
       "      <td>1.005167</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>23</td>\n",
       "      <td>1.006644</td>\n",
       "      <td>1.021864</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>24</td>\n",
       "      <td>1.037011</td>\n",
       "      <td>1.010455</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>25</td>\n",
       "      <td>1.030815</td>\n",
       "      <td>1.046789</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>26</td>\n",
       "      <td>1.002776</td>\n",
       "      <td>0.989992</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>27</td>\n",
       "      <td>0.935559</td>\n",
       "      <td>0.932230</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>28</td>\n",
       "      <td>0.999723</td>\n",
       "      <td>1.015369</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>29</td>\n",
       "      <td>1.009731</td>\n",
       "      <td>1.005167</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>30</td>\n",
       "      <td>1.006644</td>\n",
       "      <td>1.021864</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>31</td>\n",
       "      <td>0.535174</td>\n",
       "      <td>0.530890</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    day  purchase_weekday  redeem_weekday\n",
       "0     1          1.009731        1.005167\n",
       "1     2          1.006644        1.021864\n",
       "2     3          1.037011        1.010455\n",
       "3     4          1.030815        1.046789\n",
       "4     5          1.002776        0.989992\n",
       "5     6          0.935559        0.932230\n",
       "6     7          0.999723        1.015369\n",
       "7     8          1.009731        1.005167\n",
       "8     9          1.006644        1.021864\n",
       "9    10          1.037011        1.010455\n",
       "10   11          1.030815        1.046789\n",
       "11   12          1.002776        0.989992\n",
       "12   13          0.935559        0.932230\n",
       "13   14          0.999723        1.015369\n",
       "14   15          1.009731        1.005167\n",
       "15   16          1.006644        1.021864\n",
       "16   17          1.037011        1.010455\n",
       "17   18          1.030815        1.046789\n",
       "18   19          1.002776        0.989992\n",
       "19   20          0.935559        0.932230\n",
       "20   21          0.999723        1.015369\n",
       "21   22          1.009731        1.005167\n",
       "22   23          1.006644        1.021864\n",
       "23   24          1.037011        1.010455\n",
       "24   25          1.030815        1.046789\n",
       "25   26          1.002776        0.989992\n",
       "26   27          0.935559        0.932230\n",
       "27   28          0.999723        1.015369\n",
       "28   29          1.009731        1.005167\n",
       "29   30          1.006644        1.021864\n",
       "30   31          0.535174        0.530890"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "day_rate = weekday_count.drop(['weekday','report_date'], axis=1).groupby('day',as_index=False).sum()\n",
    "day_rate"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>day</th>\n",
       "      <th>total_purchase_amt</th>\n",
       "      <th>total_redeem_amt</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>3.253391e+08</td>\n",
       "      <td>2.347676e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>2.481255e+08</td>\n",
       "      <td>2.186074e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>2.994808e+08</td>\n",
       "      <td>2.968247e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>3.159802e+08</td>\n",
       "      <td>2.925598e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>3.286272e+08</td>\n",
       "      <td>2.552484e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>6</td>\n",
       "      <td>2.998453e+08</td>\n",
       "      <td>2.460958e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>7</td>\n",
       "      <td>2.836725e+08</td>\n",
       "      <td>2.374837e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>8</td>\n",
       "      <td>2.918664e+08</td>\n",
       "      <td>2.475255e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>9</td>\n",
       "      <td>2.856603e+08</td>\n",
       "      <td>2.440269e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>10</td>\n",
       "      <td>3.446347e+08</td>\n",
       "      <td>2.593854e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>11</td>\n",
       "      <td>2.864396e+08</td>\n",
       "      <td>3.051408e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>12</td>\n",
       "      <td>2.747103e+08</td>\n",
       "      <td>2.548406e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>13</td>\n",
       "      <td>2.479819e+08</td>\n",
       "      <td>2.740102e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>14</td>\n",
       "      <td>2.708833e+08</td>\n",
       "      <td>2.950661e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>15</td>\n",
       "      <td>2.958162e+08</td>\n",
       "      <td>2.302103e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>16</td>\n",
       "      <td>3.144102e+08</td>\n",
       "      <td>3.124890e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>17</td>\n",
       "      <td>2.565208e+08</td>\n",
       "      <td>2.987040e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>18</td>\n",
       "      <td>2.803201e+08</td>\n",
       "      <td>2.798990e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>19</td>\n",
       "      <td>2.836917e+08</td>\n",
       "      <td>2.608026e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>20</td>\n",
       "      <td>2.911061e+08</td>\n",
       "      <td>2.367789e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>21</td>\n",
       "      <td>2.815229e+08</td>\n",
       "      <td>2.817788e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>22</td>\n",
       "      <td>2.430277e+08</td>\n",
       "      <td>2.612727e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>23</td>\n",
       "      <td>2.282969e+08</td>\n",
       "      <td>2.625709e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>24</td>\n",
       "      <td>2.407172e+08</td>\n",
       "      <td>2.973243e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>25</td>\n",
       "      <td>2.430157e+08</td>\n",
       "      <td>3.156773e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>26</td>\n",
       "      <td>2.503822e+08</td>\n",
       "      <td>3.116598e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>27</td>\n",
       "      <td>2.383337e+08</td>\n",
       "      <td>3.178620e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>28</td>\n",
       "      <td>2.662850e+08</td>\n",
       "      <td>3.460569e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>29</td>\n",
       "      <td>2.443095e+08</td>\n",
       "      <td>2.691366e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>30</td>\n",
       "      <td>2.393089e+08</td>\n",
       "      <td>2.937321e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>31</td>\n",
       "      <td>2.531319e+08</td>\n",
       "      <td>2.842130e+08</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    day  total_purchase_amt  total_redeem_amt\n",
       "0     1        3.253391e+08      2.347676e+08\n",
       "1     2        2.481255e+08      2.186074e+08\n",
       "2     3        2.994808e+08      2.968247e+08\n",
       "3     4        3.159802e+08      2.925598e+08\n",
       "4     5        3.286272e+08      2.552484e+08\n",
       "5     6        2.998453e+08      2.460958e+08\n",
       "6     7        2.836725e+08      2.374837e+08\n",
       "7     8        2.918664e+08      2.475255e+08\n",
       "8     9        2.856603e+08      2.440269e+08\n",
       "9    10        3.446347e+08      2.593854e+08\n",
       "10   11        2.864396e+08      3.051408e+08\n",
       "11   12        2.747103e+08      2.548406e+08\n",
       "12   13        2.479819e+08      2.740102e+08\n",
       "13   14        2.708833e+08      2.950661e+08\n",
       "14   15        2.958162e+08      2.302103e+08\n",
       "15   16        3.144102e+08      3.124890e+08\n",
       "16   17        2.565208e+08      2.987040e+08\n",
       "17   18        2.803201e+08      2.798990e+08\n",
       "18   19        2.836917e+08      2.608026e+08\n",
       "19   20        2.911061e+08      2.367789e+08\n",
       "20   21        2.815229e+08      2.817788e+08\n",
       "21   22        2.430277e+08      2.612727e+08\n",
       "22   23        2.282969e+08      2.625709e+08\n",
       "23   24        2.407172e+08      2.973243e+08\n",
       "24   25        2.430157e+08      3.156773e+08\n",
       "25   26        2.503822e+08      3.116598e+08\n",
       "26   27        2.383337e+08      3.178620e+08\n",
       "27   28        2.662850e+08      3.460569e+08\n",
       "28   29        2.443095e+08      2.691366e+08\n",
       "29   30        2.393089e+08      2.937321e+08\n",
       "30   31        2.531319e+08      2.842130e+08"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 按照日期day计算均值，即1号的均值，2号的均值。。。\n",
    "day_mean = total_balance[['day','total_purchase_amt','total_redeem_amt']].groupby('day', as_index=False).mean()\n",
    "day_mean"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>day</th>\n",
       "      <th>total_purchase_amt</th>\n",
       "      <th>total_redeem_amt</th>\n",
       "      <th>purchase_weekday</th>\n",
       "      <th>redeem_weekday</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>3.222038e+08</td>\n",
       "      <td>2.335608e+08</td>\n",
       "      <td>1.009731</td>\n",
       "      <td>1.005167</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>2.464879e+08</td>\n",
       "      <td>2.139300e+08</td>\n",
       "      <td>1.006644</td>\n",
       "      <td>1.021864</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>2.887923e+08</td>\n",
       "      <td>2.937537e+08</td>\n",
       "      <td>1.037011</td>\n",
       "      <td>1.010455</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>3.065345e+08</td>\n",
       "      <td>2.794832e+08</td>\n",
       "      <td>1.030815</td>\n",
       "      <td>1.046789</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>3.277176e+08</td>\n",
       "      <td>2.578287e+08</td>\n",
       "      <td>1.002776</td>\n",
       "      <td>0.989992</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>6</td>\n",
       "      <td>3.204986e+08</td>\n",
       "      <td>2.639860e+08</td>\n",
       "      <td>0.935559</td>\n",
       "      <td>0.932230</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>7</td>\n",
       "      <td>2.837511e+08</td>\n",
       "      <td>2.338892e+08</td>\n",
       "      <td>0.999723</td>\n",
       "      <td>1.015369</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>8</td>\n",
       "      <td>2.890537e+08</td>\n",
       "      <td>2.462531e+08</td>\n",
       "      <td>1.009731</td>\n",
       "      <td>1.005167</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>9</td>\n",
       "      <td>2.837750e+08</td>\n",
       "      <td>2.388057e+08</td>\n",
       "      <td>1.006644</td>\n",
       "      <td>1.021864</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>10</td>\n",
       "      <td>3.323346e+08</td>\n",
       "      <td>2.567017e+08</td>\n",
       "      <td>1.037011</td>\n",
       "      <td>1.010455</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>11</td>\n",
       "      <td>2.778770e+08</td>\n",
       "      <td>2.915018e+08</td>\n",
       "      <td>1.030815</td>\n",
       "      <td>1.046789</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>12</td>\n",
       "      <td>2.739499e+08</td>\n",
       "      <td>2.574168e+08</td>\n",
       "      <td>1.002776</td>\n",
       "      <td>0.989992</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>13</td>\n",
       "      <td>2.650629e+08</td>\n",
       "      <td>2.939297e+08</td>\n",
       "      <td>0.935559</td>\n",
       "      <td>0.932230</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>14</td>\n",
       "      <td>2.709584e+08</td>\n",
       "      <td>2.906000e+08</td>\n",
       "      <td>0.999723</td>\n",
       "      <td>1.015369</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>15</td>\n",
       "      <td>2.929654e+08</td>\n",
       "      <td>2.290269e+08</td>\n",
       "      <td>1.009731</td>\n",
       "      <td>1.005167</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>16</td>\n",
       "      <td>3.123351e+08</td>\n",
       "      <td>3.058029e+08</td>\n",
       "      <td>1.006644</td>\n",
       "      <td>1.021864</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>17</td>\n",
       "      <td>2.473655e+08</td>\n",
       "      <td>2.956135e+08</td>\n",
       "      <td>1.037011</td>\n",
       "      <td>1.010455</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>18</td>\n",
       "      <td>2.719404e+08</td>\n",
       "      <td>2.673883e+08</td>\n",
       "      <td>1.030815</td>\n",
       "      <td>1.046789</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>19</td>\n",
       "      <td>2.829065e+08</td>\n",
       "      <td>2.634391e+08</td>\n",
       "      <td>1.002776</td>\n",
       "      <td>0.989992</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>20</td>\n",
       "      <td>3.111575e+08</td>\n",
       "      <td>2.539918e+08</td>\n",
       "      <td>0.935559</td>\n",
       "      <td>0.932230</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>21</td>\n",
       "      <td>2.816010e+08</td>\n",
       "      <td>2.775138e+08</td>\n",
       "      <td>0.999723</td>\n",
       "      <td>1.015369</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>22</td>\n",
       "      <td>2.406857e+08</td>\n",
       "      <td>2.599297e+08</td>\n",
       "      <td>1.009731</td>\n",
       "      <td>1.005167</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>23</td>\n",
       "      <td>2.267902e+08</td>\n",
       "      <td>2.569529e+08</td>\n",
       "      <td>1.006644</td>\n",
       "      <td>1.021864</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>24</td>\n",
       "      <td>2.321259e+08</td>\n",
       "      <td>2.942481e+08</td>\n",
       "      <td>1.037011</td>\n",
       "      <td>1.010455</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>25</td>\n",
       "      <td>2.357512e+08</td>\n",
       "      <td>3.015674e+08</td>\n",
       "      <td>1.030815</td>\n",
       "      <td>1.046789</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>26</td>\n",
       "      <td>2.496891e+08</td>\n",
       "      <td>3.148104e+08</td>\n",
       "      <td>1.002776</td>\n",
       "      <td>0.989992</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>27</td>\n",
       "      <td>2.547501e+08</td>\n",
       "      <td>3.409693e+08</td>\n",
       "      <td>0.935559</td>\n",
       "      <td>0.932230</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>28</td>\n",
       "      <td>2.663588e+08</td>\n",
       "      <td>3.408189e+08</td>\n",
       "      <td>0.999723</td>\n",
       "      <td>1.015369</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>29</td>\n",
       "      <td>2.419552e+08</td>\n",
       "      <td>2.677531e+08</td>\n",
       "      <td>1.009731</td>\n",
       "      <td>1.005167</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>30</td>\n",
       "      <td>2.377294e+08</td>\n",
       "      <td>2.874474e+08</td>\n",
       "      <td>1.006644</td>\n",
       "      <td>1.021864</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>31</td>\n",
       "      <td>4.729902e+08</td>\n",
       "      <td>5.353523e+08</td>\n",
       "      <td>0.535174</td>\n",
       "      <td>0.530890</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    day  total_purchase_amt  total_redeem_amt  purchase_weekday  \\\n",
       "0     1        3.222038e+08      2.335608e+08          1.009731   \n",
       "1     2        2.464879e+08      2.139300e+08          1.006644   \n",
       "2     3        2.887923e+08      2.937537e+08          1.037011   \n",
       "3     4        3.065345e+08      2.794832e+08          1.030815   \n",
       "4     5        3.277176e+08      2.578287e+08          1.002776   \n",
       "5     6        3.204986e+08      2.639860e+08          0.935559   \n",
       "6     7        2.837511e+08      2.338892e+08          0.999723   \n",
       "7     8        2.890537e+08      2.462531e+08          1.009731   \n",
       "8     9        2.837750e+08      2.388057e+08          1.006644   \n",
       "9    10        3.323346e+08      2.567017e+08          1.037011   \n",
       "10   11        2.778770e+08      2.915018e+08          1.030815   \n",
       "11   12        2.739499e+08      2.574168e+08          1.002776   \n",
       "12   13        2.650629e+08      2.939297e+08          0.935559   \n",
       "13   14        2.709584e+08      2.906000e+08          0.999723   \n",
       "14   15        2.929654e+08      2.290269e+08          1.009731   \n",
       "15   16        3.123351e+08      3.058029e+08          1.006644   \n",
       "16   17        2.473655e+08      2.956135e+08          1.037011   \n",
       "17   18        2.719404e+08      2.673883e+08          1.030815   \n",
       "18   19        2.829065e+08      2.634391e+08          1.002776   \n",
       "19   20        3.111575e+08      2.539918e+08          0.935559   \n",
       "20   21        2.816010e+08      2.775138e+08          0.999723   \n",
       "21   22        2.406857e+08      2.599297e+08          1.009731   \n",
       "22   23        2.267902e+08      2.569529e+08          1.006644   \n",
       "23   24        2.321259e+08      2.942481e+08          1.037011   \n",
       "24   25        2.357512e+08      3.015674e+08          1.030815   \n",
       "25   26        2.496891e+08      3.148104e+08          1.002776   \n",
       "26   27        2.547501e+08      3.409693e+08          0.935559   \n",
       "27   28        2.663588e+08      3.408189e+08          0.999723   \n",
       "28   29        2.419552e+08      2.677531e+08          1.009731   \n",
       "29   30        2.377294e+08      2.874474e+08          1.006644   \n",
       "30   31        4.729902e+08      5.353523e+08          0.535174   \n",
       "\n",
       "    redeem_weekday  \n",
       "0         1.005167  \n",
       "1         1.021864  \n",
       "2         1.010455  \n",
       "3         1.046789  \n",
       "4         0.989992  \n",
       "5         0.932230  \n",
       "6         1.015369  \n",
       "7         1.005167  \n",
       "8         1.021864  \n",
       "9         1.010455  \n",
       "10        1.046789  \n",
       "11        0.989992  \n",
       "12        0.932230  \n",
       "13        1.015369  \n",
       "14        1.005167  \n",
       "15        1.021864  \n",
       "16        1.010455  \n",
       "17        1.046789  \n",
       "18        0.989992  \n",
       "19        0.932230  \n",
       "20        1.015369  \n",
       "21        1.005167  \n",
       "22        1.021864  \n",
       "23        1.010455  \n",
       "24        1.046789  \n",
       "25        0.989992  \n",
       "26        0.932230  \n",
       "27        1.015369  \n",
       "28        1.005167  \n",
       "29        1.021864  \n",
       "30        0.530890  "
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "day_pred = pd.merge(day_mean, day_rate,on='day',how='left')\n",
    "day_pred['total_purchase_amt'] /= day_pred['purchase_weekday']\n",
    "day_pred['total_redeem_amt'] /= day_pred['redeem_weekday']\n",
    "day_pred # 除完以后纯净的base"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>day</th>\n",
       "      <th>total_purchase_amt</th>\n",
       "      <th>total_redeem_amt</th>\n",
       "      <th>purchase_weekday</th>\n",
       "      <th>redeem_weekday</th>\n",
       "      <th>report_date</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>3.222038e+08</td>\n",
       "      <td>2.335608e+08</td>\n",
       "      <td>1.009731</td>\n",
       "      <td>1.005167</td>\n",
       "      <td>2014-09-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>2.464879e+08</td>\n",
       "      <td>2.139300e+08</td>\n",
       "      <td>1.006644</td>\n",
       "      <td>1.021864</td>\n",
       "      <td>2014-09-02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>2.887923e+08</td>\n",
       "      <td>2.937537e+08</td>\n",
       "      <td>1.037011</td>\n",
       "      <td>1.010455</td>\n",
       "      <td>2014-09-03</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>3.065345e+08</td>\n",
       "      <td>2.794832e+08</td>\n",
       "      <td>1.030815</td>\n",
       "      <td>1.046789</td>\n",
       "      <td>2014-09-04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>3.277176e+08</td>\n",
       "      <td>2.578287e+08</td>\n",
       "      <td>1.002776</td>\n",
       "      <td>0.989992</td>\n",
       "      <td>2014-09-05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>6</td>\n",
       "      <td>3.204986e+08</td>\n",
       "      <td>2.639860e+08</td>\n",
       "      <td>0.935559</td>\n",
       "      <td>0.932230</td>\n",
       "      <td>2014-09-06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>7</td>\n",
       "      <td>2.837511e+08</td>\n",
       "      <td>2.338892e+08</td>\n",
       "      <td>0.999723</td>\n",
       "      <td>1.015369</td>\n",
       "      <td>2014-09-07</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>8</td>\n",
       "      <td>2.890537e+08</td>\n",
       "      <td>2.462531e+08</td>\n",
       "      <td>1.009731</td>\n",
       "      <td>1.005167</td>\n",
       "      <td>2014-09-08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>9</td>\n",
       "      <td>2.837750e+08</td>\n",
       "      <td>2.388057e+08</td>\n",
       "      <td>1.006644</td>\n",
       "      <td>1.021864</td>\n",
       "      <td>2014-09-09</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>10</td>\n",
       "      <td>3.323346e+08</td>\n",
       "      <td>2.567017e+08</td>\n",
       "      <td>1.037011</td>\n",
       "      <td>1.010455</td>\n",
       "      <td>2014-09-10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>11</td>\n",
       "      <td>2.778770e+08</td>\n",
       "      <td>2.915018e+08</td>\n",
       "      <td>1.030815</td>\n",
       "      <td>1.046789</td>\n",
       "      <td>2014-09-11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>12</td>\n",
       "      <td>2.739499e+08</td>\n",
       "      <td>2.574168e+08</td>\n",
       "      <td>1.002776</td>\n",
       "      <td>0.989992</td>\n",
       "      <td>2014-09-12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>13</td>\n",
       "      <td>2.650629e+08</td>\n",
       "      <td>2.939297e+08</td>\n",
       "      <td>0.935559</td>\n",
       "      <td>0.932230</td>\n",
       "      <td>2014-09-13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>14</td>\n",
       "      <td>2.709584e+08</td>\n",
       "      <td>2.906000e+08</td>\n",
       "      <td>0.999723</td>\n",
       "      <td>1.015369</td>\n",
       "      <td>2014-09-14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>15</td>\n",
       "      <td>2.929654e+08</td>\n",
       "      <td>2.290269e+08</td>\n",
       "      <td>1.009731</td>\n",
       "      <td>1.005167</td>\n",
       "      <td>2014-09-15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>16</td>\n",
       "      <td>3.123351e+08</td>\n",
       "      <td>3.058029e+08</td>\n",
       "      <td>1.006644</td>\n",
       "      <td>1.021864</td>\n",
       "      <td>2014-09-16</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>17</td>\n",
       "      <td>2.473655e+08</td>\n",
       "      <td>2.956135e+08</td>\n",
       "      <td>1.037011</td>\n",
       "      <td>1.010455</td>\n",
       "      <td>2014-09-17</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>18</td>\n",
       "      <td>2.719404e+08</td>\n",
       "      <td>2.673883e+08</td>\n",
       "      <td>1.030815</td>\n",
       "      <td>1.046789</td>\n",
       "      <td>2014-09-18</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>19</td>\n",
       "      <td>2.829065e+08</td>\n",
       "      <td>2.634391e+08</td>\n",
       "      <td>1.002776</td>\n",
       "      <td>0.989992</td>\n",
       "      <td>2014-09-19</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>20</td>\n",
       "      <td>3.111575e+08</td>\n",
       "      <td>2.539918e+08</td>\n",
       "      <td>0.935559</td>\n",
       "      <td>0.932230</td>\n",
       "      <td>2014-09-20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>21</td>\n",
       "      <td>2.816010e+08</td>\n",
       "      <td>2.775138e+08</td>\n",
       "      <td>0.999723</td>\n",
       "      <td>1.015369</td>\n",
       "      <td>2014-09-21</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>22</td>\n",
       "      <td>2.406857e+08</td>\n",
       "      <td>2.599297e+08</td>\n",
       "      <td>1.009731</td>\n",
       "      <td>1.005167</td>\n",
       "      <td>2014-09-22</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>23</td>\n",
       "      <td>2.267902e+08</td>\n",
       "      <td>2.569529e+08</td>\n",
       "      <td>1.006644</td>\n",
       "      <td>1.021864</td>\n",
       "      <td>2014-09-23</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>24</td>\n",
       "      <td>2.321259e+08</td>\n",
       "      <td>2.942481e+08</td>\n",
       "      <td>1.037011</td>\n",
       "      <td>1.010455</td>\n",
       "      <td>2014-09-24</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>25</td>\n",
       "      <td>2.357512e+08</td>\n",
       "      <td>3.015674e+08</td>\n",
       "      <td>1.030815</td>\n",
       "      <td>1.046789</td>\n",
       "      <td>2014-09-25</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>26</td>\n",
       "      <td>2.496891e+08</td>\n",
       "      <td>3.148104e+08</td>\n",
       "      <td>1.002776</td>\n",
       "      <td>0.989992</td>\n",
       "      <td>2014-09-26</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>27</td>\n",
       "      <td>2.547501e+08</td>\n",
       "      <td>3.409693e+08</td>\n",
       "      <td>0.935559</td>\n",
       "      <td>0.932230</td>\n",
       "      <td>2014-09-27</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>28</td>\n",
       "      <td>2.663588e+08</td>\n",
       "      <td>3.408189e+08</td>\n",
       "      <td>0.999723</td>\n",
       "      <td>1.015369</td>\n",
       "      <td>2014-09-28</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>29</td>\n",
       "      <td>2.419552e+08</td>\n",
       "      <td>2.677531e+08</td>\n",
       "      <td>1.009731</td>\n",
       "      <td>1.005167</td>\n",
       "      <td>2014-09-29</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>30</td>\n",
       "      <td>2.377294e+08</td>\n",
       "      <td>2.874474e+08</td>\n",
       "      <td>1.006644</td>\n",
       "      <td>1.021864</td>\n",
       "      <td>2014-09-30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>31</td>\n",
       "      <td>4.729902e+08</td>\n",
       "      <td>5.353523e+08</td>\n",
       "      <td>0.535174</td>\n",
       "      <td>0.530890</td>\n",
       "      <td>NaT</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    day  total_purchase_amt  total_redeem_amt  purchase_weekday  \\\n",
       "0     1        3.222038e+08      2.335608e+08          1.009731   \n",
       "1     2        2.464879e+08      2.139300e+08          1.006644   \n",
       "2     3        2.887923e+08      2.937537e+08          1.037011   \n",
       "3     4        3.065345e+08      2.794832e+08          1.030815   \n",
       "4     5        3.277176e+08      2.578287e+08          1.002776   \n",
       "5     6        3.204986e+08      2.639860e+08          0.935559   \n",
       "6     7        2.837511e+08      2.338892e+08          0.999723   \n",
       "7     8        2.890537e+08      2.462531e+08          1.009731   \n",
       "8     9        2.837750e+08      2.388057e+08          1.006644   \n",
       "9    10        3.323346e+08      2.567017e+08          1.037011   \n",
       "10   11        2.778770e+08      2.915018e+08          1.030815   \n",
       "11   12        2.739499e+08      2.574168e+08          1.002776   \n",
       "12   13        2.650629e+08      2.939297e+08          0.935559   \n",
       "13   14        2.709584e+08      2.906000e+08          0.999723   \n",
       "14   15        2.929654e+08      2.290269e+08          1.009731   \n",
       "15   16        3.123351e+08      3.058029e+08          1.006644   \n",
       "16   17        2.473655e+08      2.956135e+08          1.037011   \n",
       "17   18        2.719404e+08      2.673883e+08          1.030815   \n",
       "18   19        2.829065e+08      2.634391e+08          1.002776   \n",
       "19   20        3.111575e+08      2.539918e+08          0.935559   \n",
       "20   21        2.816010e+08      2.775138e+08          0.999723   \n",
       "21   22        2.406857e+08      2.599297e+08          1.009731   \n",
       "22   23        2.267902e+08      2.569529e+08          1.006644   \n",
       "23   24        2.321259e+08      2.942481e+08          1.037011   \n",
       "24   25        2.357512e+08      3.015674e+08          1.030815   \n",
       "25   26        2.496891e+08      3.148104e+08          1.002776   \n",
       "26   27        2.547501e+08      3.409693e+08          0.935559   \n",
       "27   28        2.663588e+08      3.408189e+08          0.999723   \n",
       "28   29        2.419552e+08      2.677531e+08          1.009731   \n",
       "29   30        2.377294e+08      2.874474e+08          1.006644   \n",
       "30   31        4.729902e+08      5.353523e+08          0.535174   \n",
       "\n",
       "    redeem_weekday report_date  \n",
       "0         1.005167  2014-09-01  \n",
       "1         1.021864  2014-09-02  \n",
       "2         1.010455  2014-09-03  \n",
       "3         1.046789  2014-09-04  \n",
       "4         0.989992  2014-09-05  \n",
       "5         0.932230  2014-09-06  \n",
       "6         1.015369  2014-09-07  \n",
       "7         1.005167  2014-09-08  \n",
       "8         1.021864  2014-09-09  \n",
       "9         1.010455  2014-09-10  \n",
       "10        1.046789  2014-09-11  \n",
       "11        0.989992  2014-09-12  \n",
       "12        0.932230  2014-09-13  \n",
       "13        1.015369  2014-09-14  \n",
       "14        1.005167  2014-09-15  \n",
       "15        1.021864  2014-09-16  \n",
       "16        1.010455  2014-09-17  \n",
       "17        1.046789  2014-09-18  \n",
       "18        0.989992  2014-09-19  \n",
       "19        0.932230  2014-09-20  \n",
       "20        1.015369  2014-09-21  \n",
       "21        1.005167  2014-09-22  \n",
       "22        1.021864  2014-09-23  \n",
       "23        1.010455  2014-09-24  \n",
       "24        1.046789  2014-09-25  \n",
       "25        0.989992  2014-09-26  \n",
       "26        0.932230  2014-09-27  \n",
       "27        1.015369  2014-09-28  \n",
       "28        1.005167  2014-09-29  \n",
       "29        1.021864  2014-09-30  \n",
       "30        0.530890         NaT  "
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "for index,row in day_pred.iterrows():\n",
    "    if row['day'] == 31:\n",
    "        break\n",
    "    # 添加日期字段report_date\n",
    "    day_pred.loc[index, 'report_date'] = pd.to_datetime('2014/09/' + str(int(row['day'])))\n",
    "day_pred"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>day</th>\n",
       "      <th>total_purchase_amt</th>\n",
       "      <th>total_redeem_amt</th>\n",
       "      <th>purchase_weekday</th>\n",
       "      <th>redeem_weekday</th>\n",
       "      <th>report_date</th>\n",
       "      <th>weekday</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>3.222038e+08</td>\n",
       "      <td>2.335608e+08</td>\n",
       "      <td>1.009731</td>\n",
       "      <td>1.005167</td>\n",
       "      <td>2014-09-01</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>2.464879e+08</td>\n",
       "      <td>2.139300e+08</td>\n",
       "      <td>1.006644</td>\n",
       "      <td>1.021864</td>\n",
       "      <td>2014-09-02</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>2.887923e+08</td>\n",
       "      <td>2.937537e+08</td>\n",
       "      <td>1.037011</td>\n",
       "      <td>1.010455</td>\n",
       "      <td>2014-09-03</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>3.065345e+08</td>\n",
       "      <td>2.794832e+08</td>\n",
       "      <td>1.030815</td>\n",
       "      <td>1.046789</td>\n",
       "      <td>2014-09-04</td>\n",
       "      <td>3.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>3.277176e+08</td>\n",
       "      <td>2.578287e+08</td>\n",
       "      <td>1.002776</td>\n",
       "      <td>0.989992</td>\n",
       "      <td>2014-09-05</td>\n",
       "      <td>4.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>6</td>\n",
       "      <td>3.204986e+08</td>\n",
       "      <td>2.639860e+08</td>\n",
       "      <td>0.935559</td>\n",
       "      <td>0.932230</td>\n",
       "      <td>2014-09-06</td>\n",
       "      <td>5.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>7</td>\n",
       "      <td>2.837511e+08</td>\n",
       "      <td>2.338892e+08</td>\n",
       "      <td>0.999723</td>\n",
       "      <td>1.015369</td>\n",
       "      <td>2014-09-07</td>\n",
       "      <td>6.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>8</td>\n",
       "      <td>2.890537e+08</td>\n",
       "      <td>2.462531e+08</td>\n",
       "      <td>1.009731</td>\n",
       "      <td>1.005167</td>\n",
       "      <td>2014-09-08</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>9</td>\n",
       "      <td>2.837750e+08</td>\n",
       "      <td>2.388057e+08</td>\n",
       "      <td>1.006644</td>\n",
       "      <td>1.021864</td>\n",
       "      <td>2014-09-09</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>10</td>\n",
       "      <td>3.323346e+08</td>\n",
       "      <td>2.567017e+08</td>\n",
       "      <td>1.037011</td>\n",
       "      <td>1.010455</td>\n",
       "      <td>2014-09-10</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>11</td>\n",
       "      <td>2.778770e+08</td>\n",
       "      <td>2.915018e+08</td>\n",
       "      <td>1.030815</td>\n",
       "      <td>1.046789</td>\n",
       "      <td>2014-09-11</td>\n",
       "      <td>3.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>12</td>\n",
       "      <td>2.739499e+08</td>\n",
       "      <td>2.574168e+08</td>\n",
       "      <td>1.002776</td>\n",
       "      <td>0.989992</td>\n",
       "      <td>2014-09-12</td>\n",
       "      <td>4.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>13</td>\n",
       "      <td>2.650629e+08</td>\n",
       "      <td>2.939297e+08</td>\n",
       "      <td>0.935559</td>\n",
       "      <td>0.932230</td>\n",
       "      <td>2014-09-13</td>\n",
       "      <td>5.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>14</td>\n",
       "      <td>2.709584e+08</td>\n",
       "      <td>2.906000e+08</td>\n",
       "      <td>0.999723</td>\n",
       "      <td>1.015369</td>\n",
       "      <td>2014-09-14</td>\n",
       "      <td>6.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>15</td>\n",
       "      <td>2.929654e+08</td>\n",
       "      <td>2.290269e+08</td>\n",
       "      <td>1.009731</td>\n",
       "      <td>1.005167</td>\n",
       "      <td>2014-09-15</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>16</td>\n",
       "      <td>3.123351e+08</td>\n",
       "      <td>3.058029e+08</td>\n",
       "      <td>1.006644</td>\n",
       "      <td>1.021864</td>\n",
       "      <td>2014-09-16</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>17</td>\n",
       "      <td>2.473655e+08</td>\n",
       "      <td>2.956135e+08</td>\n",
       "      <td>1.037011</td>\n",
       "      <td>1.010455</td>\n",
       "      <td>2014-09-17</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>18</td>\n",
       "      <td>2.719404e+08</td>\n",
       "      <td>2.673883e+08</td>\n",
       "      <td>1.030815</td>\n",
       "      <td>1.046789</td>\n",
       "      <td>2014-09-18</td>\n",
       "      <td>3.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>19</td>\n",
       "      <td>2.829065e+08</td>\n",
       "      <td>2.634391e+08</td>\n",
       "      <td>1.002776</td>\n",
       "      <td>0.989992</td>\n",
       "      <td>2014-09-19</td>\n",
       "      <td>4.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>20</td>\n",
       "      <td>3.111575e+08</td>\n",
       "      <td>2.539918e+08</td>\n",
       "      <td>0.935559</td>\n",
       "      <td>0.932230</td>\n",
       "      <td>2014-09-20</td>\n",
       "      <td>5.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>21</td>\n",
       "      <td>2.816010e+08</td>\n",
       "      <td>2.775138e+08</td>\n",
       "      <td>0.999723</td>\n",
       "      <td>1.015369</td>\n",
       "      <td>2014-09-21</td>\n",
       "      <td>6.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>22</td>\n",
       "      <td>2.406857e+08</td>\n",
       "      <td>2.599297e+08</td>\n",
       "      <td>1.009731</td>\n",
       "      <td>1.005167</td>\n",
       "      <td>2014-09-22</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>23</td>\n",
       "      <td>2.267902e+08</td>\n",
       "      <td>2.569529e+08</td>\n",
       "      <td>1.006644</td>\n",
       "      <td>1.021864</td>\n",
       "      <td>2014-09-23</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>24</td>\n",
       "      <td>2.321259e+08</td>\n",
       "      <td>2.942481e+08</td>\n",
       "      <td>1.037011</td>\n",
       "      <td>1.010455</td>\n",
       "      <td>2014-09-24</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>25</td>\n",
       "      <td>2.357512e+08</td>\n",
       "      <td>3.015674e+08</td>\n",
       "      <td>1.030815</td>\n",
       "      <td>1.046789</td>\n",
       "      <td>2014-09-25</td>\n",
       "      <td>3.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>26</td>\n",
       "      <td>2.496891e+08</td>\n",
       "      <td>3.148104e+08</td>\n",
       "      <td>1.002776</td>\n",
       "      <td>0.989992</td>\n",
       "      <td>2014-09-26</td>\n",
       "      <td>4.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>27</td>\n",
       "      <td>2.547501e+08</td>\n",
       "      <td>3.409693e+08</td>\n",
       "      <td>0.935559</td>\n",
       "      <td>0.932230</td>\n",
       "      <td>2014-09-27</td>\n",
       "      <td>5.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>28</td>\n",
       "      <td>2.663588e+08</td>\n",
       "      <td>3.408189e+08</td>\n",
       "      <td>0.999723</td>\n",
       "      <td>1.015369</td>\n",
       "      <td>2014-09-28</td>\n",
       "      <td>6.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>29</td>\n",
       "      <td>2.419552e+08</td>\n",
       "      <td>2.677531e+08</td>\n",
       "      <td>1.009731</td>\n",
       "      <td>1.005167</td>\n",
       "      <td>2014-09-29</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>30</td>\n",
       "      <td>2.377294e+08</td>\n",
       "      <td>2.874474e+08</td>\n",
       "      <td>1.006644</td>\n",
       "      <td>1.021864</td>\n",
       "      <td>2014-09-30</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>31</td>\n",
       "      <td>4.729902e+08</td>\n",
       "      <td>5.353523e+08</td>\n",
       "      <td>0.535174</td>\n",
       "      <td>0.530890</td>\n",
       "      <td>NaT</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    day  total_purchase_amt  total_redeem_amt  purchase_weekday  \\\n",
       "0     1        3.222038e+08      2.335608e+08          1.009731   \n",
       "1     2        2.464879e+08      2.139300e+08          1.006644   \n",
       "2     3        2.887923e+08      2.937537e+08          1.037011   \n",
       "3     4        3.065345e+08      2.794832e+08          1.030815   \n",
       "4     5        3.277176e+08      2.578287e+08          1.002776   \n",
       "5     6        3.204986e+08      2.639860e+08          0.935559   \n",
       "6     7        2.837511e+08      2.338892e+08          0.999723   \n",
       "7     8        2.890537e+08      2.462531e+08          1.009731   \n",
       "8     9        2.837750e+08      2.388057e+08          1.006644   \n",
       "9    10        3.323346e+08      2.567017e+08          1.037011   \n",
       "10   11        2.778770e+08      2.915018e+08          1.030815   \n",
       "11   12        2.739499e+08      2.574168e+08          1.002776   \n",
       "12   13        2.650629e+08      2.939297e+08          0.935559   \n",
       "13   14        2.709584e+08      2.906000e+08          0.999723   \n",
       "14   15        2.929654e+08      2.290269e+08          1.009731   \n",
       "15   16        3.123351e+08      3.058029e+08          1.006644   \n",
       "16   17        2.473655e+08      2.956135e+08          1.037011   \n",
       "17   18        2.719404e+08      2.673883e+08          1.030815   \n",
       "18   19        2.829065e+08      2.634391e+08          1.002776   \n",
       "19   20        3.111575e+08      2.539918e+08          0.935559   \n",
       "20   21        2.816010e+08      2.775138e+08          0.999723   \n",
       "21   22        2.406857e+08      2.599297e+08          1.009731   \n",
       "22   23        2.267902e+08      2.569529e+08          1.006644   \n",
       "23   24        2.321259e+08      2.942481e+08          1.037011   \n",
       "24   25        2.357512e+08      3.015674e+08          1.030815   \n",
       "25   26        2.496891e+08      3.148104e+08          1.002776   \n",
       "26   27        2.547501e+08      3.409693e+08          0.935559   \n",
       "27   28        2.663588e+08      3.408189e+08          0.999723   \n",
       "28   29        2.419552e+08      2.677531e+08          1.009731   \n",
       "29   30        2.377294e+08      2.874474e+08          1.006644   \n",
       "30   31        4.729902e+08      5.353523e+08          0.535174   \n",
       "\n",
       "    redeem_weekday report_date  weekday  \n",
       "0         1.005167  2014-09-01      0.0  \n",
       "1         1.021864  2014-09-02      1.0  \n",
       "2         1.010455  2014-09-03      2.0  \n",
       "3         1.046789  2014-09-04      3.0  \n",
       "4         0.989992  2014-09-05      4.0  \n",
       "5         0.932230  2014-09-06      5.0  \n",
       "6         1.015369  2014-09-07      6.0  \n",
       "7         1.005167  2014-09-08      0.0  \n",
       "8         1.021864  2014-09-09      1.0  \n",
       "9         1.010455  2014-09-10      2.0  \n",
       "10        1.046789  2014-09-11      3.0  \n",
       "11        0.989992  2014-09-12      4.0  \n",
       "12        0.932230  2014-09-13      5.0  \n",
       "13        1.015369  2014-09-14      6.0  \n",
       "14        1.005167  2014-09-15      0.0  \n",
       "15        1.021864  2014-09-16      1.0  \n",
       "16        1.010455  2014-09-17      2.0  \n",
       "17        1.046789  2014-09-18      3.0  \n",
       "18        0.989992  2014-09-19      4.0  \n",
       "19        0.932230  2014-09-20      5.0  \n",
       "20        1.015369  2014-09-21      6.0  \n",
       "21        1.005167  2014-09-22      0.0  \n",
       "22        1.021864  2014-09-23      1.0  \n",
       "23        1.010455  2014-09-24      2.0  \n",
       "24        1.046789  2014-09-25      3.0  \n",
       "25        0.989992  2014-09-26      4.0  \n",
       "26        0.932230  2014-09-27      5.0  \n",
       "27        1.015369  2014-09-28      6.0  \n",
       "28        1.005167  2014-09-29      0.0  \n",
       "29        1.021864  2014-09-30      1.0  \n",
       "30        0.530890         NaT      NaN  "
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 利用周期因子，进行base*周期因子=预测结果\n",
    "day_pred['weekday'] = day_pred['report_date'].dt.weekday\n",
    "day_pred"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>day</th>\n",
       "      <th>total_purchase_amt</th>\n",
       "      <th>total_redeem_amt</th>\n",
       "      <th>report_date</th>\n",
       "      <th>weekday</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>3.222038e+08</td>\n",
       "      <td>2.335608e+08</td>\n",
       "      <td>2014-09-01</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>2.464879e+08</td>\n",
       "      <td>2.139300e+08</td>\n",
       "      <td>2014-09-02</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>2.887923e+08</td>\n",
       "      <td>2.937537e+08</td>\n",
       "      <td>2014-09-03</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>3.065345e+08</td>\n",
       "      <td>2.794832e+08</td>\n",
       "      <td>2014-09-04</td>\n",
       "      <td>3.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>3.277176e+08</td>\n",
       "      <td>2.578287e+08</td>\n",
       "      <td>2014-09-05</td>\n",
       "      <td>4.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>6</td>\n",
       "      <td>3.204986e+08</td>\n",
       "      <td>2.639860e+08</td>\n",
       "      <td>2014-09-06</td>\n",
       "      <td>5.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>7</td>\n",
       "      <td>2.837511e+08</td>\n",
       "      <td>2.338892e+08</td>\n",
       "      <td>2014-09-07</td>\n",
       "      <td>6.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>8</td>\n",
       "      <td>2.890537e+08</td>\n",
       "      <td>2.462531e+08</td>\n",
       "      <td>2014-09-08</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>9</td>\n",
       "      <td>2.837750e+08</td>\n",
       "      <td>2.388057e+08</td>\n",
       "      <td>2014-09-09</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>10</td>\n",
       "      <td>3.323346e+08</td>\n",
       "      <td>2.567017e+08</td>\n",
       "      <td>2014-09-10</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>11</td>\n",
       "      <td>2.778770e+08</td>\n",
       "      <td>2.915018e+08</td>\n",
       "      <td>2014-09-11</td>\n",
       "      <td>3.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>12</td>\n",
       "      <td>2.739499e+08</td>\n",
       "      <td>2.574168e+08</td>\n",
       "      <td>2014-09-12</td>\n",
       "      <td>4.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>13</td>\n",
       "      <td>2.650629e+08</td>\n",
       "      <td>2.939297e+08</td>\n",
       "      <td>2014-09-13</td>\n",
       "      <td>5.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>14</td>\n",
       "      <td>2.709584e+08</td>\n",
       "      <td>2.906000e+08</td>\n",
       "      <td>2014-09-14</td>\n",
       "      <td>6.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>15</td>\n",
       "      <td>2.929654e+08</td>\n",
       "      <td>2.290269e+08</td>\n",
       "      <td>2014-09-15</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>16</td>\n",
       "      <td>3.123351e+08</td>\n",
       "      <td>3.058029e+08</td>\n",
       "      <td>2014-09-16</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>17</td>\n",
       "      <td>2.473655e+08</td>\n",
       "      <td>2.956135e+08</td>\n",
       "      <td>2014-09-17</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>18</td>\n",
       "      <td>2.719404e+08</td>\n",
       "      <td>2.673883e+08</td>\n",
       "      <td>2014-09-18</td>\n",
       "      <td>3.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>19</td>\n",
       "      <td>2.829065e+08</td>\n",
       "      <td>2.634391e+08</td>\n",
       "      <td>2014-09-19</td>\n",
       "      <td>4.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>20</td>\n",
       "      <td>3.111575e+08</td>\n",
       "      <td>2.539918e+08</td>\n",
       "      <td>2014-09-20</td>\n",
       "      <td>5.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>21</td>\n",
       "      <td>2.816010e+08</td>\n",
       "      <td>2.775138e+08</td>\n",
       "      <td>2014-09-21</td>\n",
       "      <td>6.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>22</td>\n",
       "      <td>2.406857e+08</td>\n",
       "      <td>2.599297e+08</td>\n",
       "      <td>2014-09-22</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>23</td>\n",
       "      <td>2.267902e+08</td>\n",
       "      <td>2.569529e+08</td>\n",
       "      <td>2014-09-23</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>24</td>\n",
       "      <td>2.321259e+08</td>\n",
       "      <td>2.942481e+08</td>\n",
       "      <td>2014-09-24</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>25</td>\n",
       "      <td>2.357512e+08</td>\n",
       "      <td>3.015674e+08</td>\n",
       "      <td>2014-09-25</td>\n",
       "      <td>3.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>26</td>\n",
       "      <td>2.496891e+08</td>\n",
       "      <td>3.148104e+08</td>\n",
       "      <td>2014-09-26</td>\n",
       "      <td>4.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>27</td>\n",
       "      <td>2.547501e+08</td>\n",
       "      <td>3.409693e+08</td>\n",
       "      <td>2014-09-27</td>\n",
       "      <td>5.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>28</td>\n",
       "      <td>2.663588e+08</td>\n",
       "      <td>3.408189e+08</td>\n",
       "      <td>2014-09-28</td>\n",
       "      <td>6.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>29</td>\n",
       "      <td>2.419552e+08</td>\n",
       "      <td>2.677531e+08</td>\n",
       "      <td>2014-09-29</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>30</td>\n",
       "      <td>2.377294e+08</td>\n",
       "      <td>2.874474e+08</td>\n",
       "      <td>2014-09-30</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>31</td>\n",
       "      <td>4.729902e+08</td>\n",
       "      <td>5.353523e+08</td>\n",
       "      <td>NaT</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    day  total_purchase_amt  total_redeem_amt report_date  weekday\n",
       "0     1        3.222038e+08      2.335608e+08  2014-09-01      0.0\n",
       "1     2        2.464879e+08      2.139300e+08  2014-09-02      1.0\n",
       "2     3        2.887923e+08      2.937537e+08  2014-09-03      2.0\n",
       "3     4        3.065345e+08      2.794832e+08  2014-09-04      3.0\n",
       "4     5        3.277176e+08      2.578287e+08  2014-09-05      4.0\n",
       "5     6        3.204986e+08      2.639860e+08  2014-09-06      5.0\n",
       "6     7        2.837511e+08      2.338892e+08  2014-09-07      6.0\n",
       "7     8        2.890537e+08      2.462531e+08  2014-09-08      0.0\n",
       "8     9        2.837750e+08      2.388057e+08  2014-09-09      1.0\n",
       "9    10        3.323346e+08      2.567017e+08  2014-09-10      2.0\n",
       "10   11        2.778770e+08      2.915018e+08  2014-09-11      3.0\n",
       "11   12        2.739499e+08      2.574168e+08  2014-09-12      4.0\n",
       "12   13        2.650629e+08      2.939297e+08  2014-09-13      5.0\n",
       "13   14        2.709584e+08      2.906000e+08  2014-09-14      6.0\n",
       "14   15        2.929654e+08      2.290269e+08  2014-09-15      0.0\n",
       "15   16        3.123351e+08      3.058029e+08  2014-09-16      1.0\n",
       "16   17        2.473655e+08      2.956135e+08  2014-09-17      2.0\n",
       "17   18        2.719404e+08      2.673883e+08  2014-09-18      3.0\n",
       "18   19        2.829065e+08      2.634391e+08  2014-09-19      4.0\n",
       "19   20        3.111575e+08      2.539918e+08  2014-09-20      5.0\n",
       "20   21        2.816010e+08      2.775138e+08  2014-09-21      6.0\n",
       "21   22        2.406857e+08      2.599297e+08  2014-09-22      0.0\n",
       "22   23        2.267902e+08      2.569529e+08  2014-09-23      1.0\n",
       "23   24        2.321259e+08      2.942481e+08  2014-09-24      2.0\n",
       "24   25        2.357512e+08      3.015674e+08  2014-09-25      3.0\n",
       "25   26        2.496891e+08      3.148104e+08  2014-09-26      4.0\n",
       "26   27        2.547501e+08      3.409693e+08  2014-09-27      5.0\n",
       "27   28        2.663588e+08      3.408189e+08  2014-09-28      6.0\n",
       "28   29        2.419552e+08      2.677531e+08  2014-09-29      0.0\n",
       "29   30        2.377294e+08      2.874474e+08  2014-09-30      1.0\n",
       "30   31        4.729902e+08      5.353523e+08         NaT      NaN"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\n",
    "day_pred = day_pred[['day','total_purchase_amt','total_redeem_amt','report_date','weekday']]\n",
    "day_pred"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>day</th>\n",
       "      <th>total_purchase_amt</th>\n",
       "      <th>total_redeem_amt</th>\n",
       "      <th>report_date</th>\n",
       "      <th>weekday</th>\n",
       "      <th>purchase_weekday</th>\n",
       "      <th>redeem_weekday</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>3.222038e+08</td>\n",
       "      <td>2.335608e+08</td>\n",
       "      <td>2014-09-01</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.185411</td>\n",
       "      <td>1.257964</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>8</td>\n",
       "      <td>2.890537e+08</td>\n",
       "      <td>2.462531e+08</td>\n",
       "      <td>2014-09-08</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.185411</td>\n",
       "      <td>1.257964</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>15</td>\n",
       "      <td>2.929654e+08</td>\n",
       "      <td>2.290269e+08</td>\n",
       "      <td>2014-09-15</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.185411</td>\n",
       "      <td>1.257964</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>22</td>\n",
       "      <td>2.406857e+08</td>\n",
       "      <td>2.599297e+08</td>\n",
       "      <td>2014-09-22</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.185411</td>\n",
       "      <td>1.257964</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>29</td>\n",
       "      <td>2.419552e+08</td>\n",
       "      <td>2.677531e+08</td>\n",
       "      <td>2014-09-29</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.185411</td>\n",
       "      <td>1.257964</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>2</td>\n",
       "      <td>2.464879e+08</td>\n",
       "      <td>2.139300e+08</td>\n",
       "      <td>2014-09-02</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.209608</td>\n",
       "      <td>1.172248</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>9</td>\n",
       "      <td>2.837750e+08</td>\n",
       "      <td>2.388057e+08</td>\n",
       "      <td>2014-09-09</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.209608</td>\n",
       "      <td>1.172248</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>16</td>\n",
       "      <td>3.123351e+08</td>\n",
       "      <td>3.058029e+08</td>\n",
       "      <td>2014-09-16</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.209608</td>\n",
       "      <td>1.172248</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>23</td>\n",
       "      <td>2.267902e+08</td>\n",
       "      <td>2.569529e+08</td>\n",
       "      <td>2014-09-23</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.209608</td>\n",
       "      <td>1.172248</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>30</td>\n",
       "      <td>2.377294e+08</td>\n",
       "      <td>2.874474e+08</td>\n",
       "      <td>2014-09-30</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.209608</td>\n",
       "      <td>1.172248</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>3</td>\n",
       "      <td>2.887923e+08</td>\n",
       "      <td>2.937537e+08</td>\n",
       "      <td>2014-09-03</td>\n",
       "      <td>2.0</td>\n",
       "      <td>1.163752</td>\n",
       "      <td>1.157944</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>10</td>\n",
       "      <td>3.323346e+08</td>\n",
       "      <td>2.567017e+08</td>\n",
       "      <td>2014-09-10</td>\n",
       "      <td>2.0</td>\n",
       "      <td>1.163752</td>\n",
       "      <td>1.157944</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>17</td>\n",
       "      <td>2.473655e+08</td>\n",
       "      <td>2.956135e+08</td>\n",
       "      <td>2014-09-17</td>\n",
       "      <td>2.0</td>\n",
       "      <td>1.163752</td>\n",
       "      <td>1.157944</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>24</td>\n",
       "      <td>2.321259e+08</td>\n",
       "      <td>2.942481e+08</td>\n",
       "      <td>2014-09-24</td>\n",
       "      <td>2.0</td>\n",
       "      <td>1.163752</td>\n",
       "      <td>1.157944</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>4</td>\n",
       "      <td>3.065345e+08</td>\n",
       "      <td>2.794832e+08</td>\n",
       "      <td>2014-09-04</td>\n",
       "      <td>3.0</td>\n",
       "      <td>1.139503</td>\n",
       "      <td>1.026762</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>11</td>\n",
       "      <td>2.778770e+08</td>\n",
       "      <td>2.915018e+08</td>\n",
       "      <td>2014-09-11</td>\n",
       "      <td>3.0</td>\n",
       "      <td>1.139503</td>\n",
       "      <td>1.026762</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>18</td>\n",
       "      <td>2.719404e+08</td>\n",
       "      <td>2.673883e+08</td>\n",
       "      <td>2014-09-18</td>\n",
       "      <td>3.0</td>\n",
       "      <td>1.139503</td>\n",
       "      <td>1.026762</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>25</td>\n",
       "      <td>2.357512e+08</td>\n",
       "      <td>3.015674e+08</td>\n",
       "      <td>2014-09-25</td>\n",
       "      <td>3.0</td>\n",
       "      <td>1.139503</td>\n",
       "      <td>1.026762</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>5</td>\n",
       "      <td>3.277176e+08</td>\n",
       "      <td>2.578287e+08</td>\n",
       "      <td>2014-09-05</td>\n",
       "      <td>4.0</td>\n",
       "      <td>0.902682</td>\n",
       "      <td>0.975445</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>12</td>\n",
       "      <td>2.739499e+08</td>\n",
       "      <td>2.574168e+08</td>\n",
       "      <td>2014-09-12</td>\n",
       "      <td>4.0</td>\n",
       "      <td>0.902682</td>\n",
       "      <td>0.975445</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>19</td>\n",
       "      <td>2.829065e+08</td>\n",
       "      <td>2.634391e+08</td>\n",
       "      <td>2014-09-19</td>\n",
       "      <td>4.0</td>\n",
       "      <td>0.902682</td>\n",
       "      <td>0.975445</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>26</td>\n",
       "      <td>2.496891e+08</td>\n",
       "      <td>3.148104e+08</td>\n",
       "      <td>2014-09-26</td>\n",
       "      <td>4.0</td>\n",
       "      <td>0.902682</td>\n",
       "      <td>0.975445</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>6</td>\n",
       "      <td>3.204986e+08</td>\n",
       "      <td>2.639860e+08</td>\n",
       "      <td>2014-09-06</td>\n",
       "      <td>5.0</td>\n",
       "      <td>0.709237</td>\n",
       "      <td>0.669791</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>13</td>\n",
       "      <td>2.650629e+08</td>\n",
       "      <td>2.939297e+08</td>\n",
       "      <td>2014-09-13</td>\n",
       "      <td>5.0</td>\n",
       "      <td>0.709237</td>\n",
       "      <td>0.669791</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>20</td>\n",
       "      <td>3.111575e+08</td>\n",
       "      <td>2.539918e+08</td>\n",
       "      <td>2014-09-20</td>\n",
       "      <td>5.0</td>\n",
       "      <td>0.709237</td>\n",
       "      <td>0.669791</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>27</td>\n",
       "      <td>2.547501e+08</td>\n",
       "      <td>3.409693e+08</td>\n",
       "      <td>2014-09-27</td>\n",
       "      <td>5.0</td>\n",
       "      <td>0.709237</td>\n",
       "      <td>0.669791</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>7</td>\n",
       "      <td>2.837511e+08</td>\n",
       "      <td>2.338892e+08</td>\n",
       "      <td>2014-09-07</td>\n",
       "      <td>6.0</td>\n",
       "      <td>0.712065</td>\n",
       "      <td>0.761712</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>14</td>\n",
       "      <td>2.709584e+08</td>\n",
       "      <td>2.906000e+08</td>\n",
       "      <td>2014-09-14</td>\n",
       "      <td>6.0</td>\n",
       "      <td>0.712065</td>\n",
       "      <td>0.761712</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>21</td>\n",
       "      <td>2.816010e+08</td>\n",
       "      <td>2.775138e+08</td>\n",
       "      <td>2014-09-21</td>\n",
       "      <td>6.0</td>\n",
       "      <td>0.712065</td>\n",
       "      <td>0.761712</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>28</td>\n",
       "      <td>2.663588e+08</td>\n",
       "      <td>3.408189e+08</td>\n",
       "      <td>2014-09-28</td>\n",
       "      <td>6.0</td>\n",
       "      <td>0.712065</td>\n",
       "      <td>0.761712</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    day  total_purchase_amt  total_redeem_amt report_date  weekday  \\\n",
       "0     1        3.222038e+08      2.335608e+08  2014-09-01      0.0   \n",
       "1     8        2.890537e+08      2.462531e+08  2014-09-08      0.0   \n",
       "2    15        2.929654e+08      2.290269e+08  2014-09-15      0.0   \n",
       "3    22        2.406857e+08      2.599297e+08  2014-09-22      0.0   \n",
       "4    29        2.419552e+08      2.677531e+08  2014-09-29      0.0   \n",
       "5     2        2.464879e+08      2.139300e+08  2014-09-02      1.0   \n",
       "6     9        2.837750e+08      2.388057e+08  2014-09-09      1.0   \n",
       "7    16        3.123351e+08      3.058029e+08  2014-09-16      1.0   \n",
       "8    23        2.267902e+08      2.569529e+08  2014-09-23      1.0   \n",
       "9    30        2.377294e+08      2.874474e+08  2014-09-30      1.0   \n",
       "10    3        2.887923e+08      2.937537e+08  2014-09-03      2.0   \n",
       "11   10        3.323346e+08      2.567017e+08  2014-09-10      2.0   \n",
       "12   17        2.473655e+08      2.956135e+08  2014-09-17      2.0   \n",
       "13   24        2.321259e+08      2.942481e+08  2014-09-24      2.0   \n",
       "14    4        3.065345e+08      2.794832e+08  2014-09-04      3.0   \n",
       "15   11        2.778770e+08      2.915018e+08  2014-09-11      3.0   \n",
       "16   18        2.719404e+08      2.673883e+08  2014-09-18      3.0   \n",
       "17   25        2.357512e+08      3.015674e+08  2014-09-25      3.0   \n",
       "18    5        3.277176e+08      2.578287e+08  2014-09-05      4.0   \n",
       "19   12        2.739499e+08      2.574168e+08  2014-09-12      4.0   \n",
       "20   19        2.829065e+08      2.634391e+08  2014-09-19      4.0   \n",
       "21   26        2.496891e+08      3.148104e+08  2014-09-26      4.0   \n",
       "22    6        3.204986e+08      2.639860e+08  2014-09-06      5.0   \n",
       "23   13        2.650629e+08      2.939297e+08  2014-09-13      5.0   \n",
       "24   20        3.111575e+08      2.539918e+08  2014-09-20      5.0   \n",
       "25   27        2.547501e+08      3.409693e+08  2014-09-27      5.0   \n",
       "26    7        2.837511e+08      2.338892e+08  2014-09-07      6.0   \n",
       "27   14        2.709584e+08      2.906000e+08  2014-09-14      6.0   \n",
       "28   21        2.816010e+08      2.775138e+08  2014-09-21      6.0   \n",
       "29   28        2.663588e+08      3.408189e+08  2014-09-28      6.0   \n",
       "\n",
       "    purchase_weekday  redeem_weekday  \n",
       "0           1.185411        1.257964  \n",
       "1           1.185411        1.257964  \n",
       "2           1.185411        1.257964  \n",
       "3           1.185411        1.257964  \n",
       "4           1.185411        1.257964  \n",
       "5           1.209608        1.172248  \n",
       "6           1.209608        1.172248  \n",
       "7           1.209608        1.172248  \n",
       "8           1.209608        1.172248  \n",
       "9           1.209608        1.172248  \n",
       "10          1.163752        1.157944  \n",
       "11          1.163752        1.157944  \n",
       "12          1.163752        1.157944  \n",
       "13          1.163752        1.157944  \n",
       "14          1.139503        1.026762  \n",
       "15          1.139503        1.026762  \n",
       "16          1.139503        1.026762  \n",
       "17          1.139503        1.026762  \n",
       "18          0.902682        0.975445  \n",
       "19          0.902682        0.975445  \n",
       "20          0.902682        0.975445  \n",
       "21          0.902682        0.975445  \n",
       "22          0.709237        0.669791  \n",
       "23          0.709237        0.669791  \n",
       "24          0.709237        0.669791  \n",
       "25          0.709237        0.669791  \n",
       "26          0.712065        0.761712  \n",
       "27          0.712065        0.761712  \n",
       "28          0.712065        0.761712  \n",
       "29          0.712065        0.761712  "
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "day_pred = pd.merge(day_pred, weekday_weight, on='weekday')\n",
    "day_pred"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>day</th>\n",
       "      <th>total_purchase_amt</th>\n",
       "      <th>total_redeem_amt</th>\n",
       "      <th>report_date</th>\n",
       "      <th>weekday</th>\n",
       "      <th>purchase_weekday</th>\n",
       "      <th>redeem_weekday</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>3.819439e+08</td>\n",
       "      <td>2.938111e+08</td>\n",
       "      <td>2014-09-01</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.185411</td>\n",
       "      <td>1.257964</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>8</td>\n",
       "      <td>3.426474e+08</td>\n",
       "      <td>3.097775e+08</td>\n",
       "      <td>2014-09-08</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.185411</td>\n",
       "      <td>1.257964</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>15</td>\n",
       "      <td>3.472844e+08</td>\n",
       "      <td>2.881076e+08</td>\n",
       "      <td>2014-09-15</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.185411</td>\n",
       "      <td>1.257964</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>22</td>\n",
       "      <td>2.853115e+08</td>\n",
       "      <td>3.269821e+08</td>\n",
       "      <td>2014-09-22</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.185411</td>\n",
       "      <td>1.257964</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>29</td>\n",
       "      <td>2.868163e+08</td>\n",
       "      <td>3.368237e+08</td>\n",
       "      <td>2014-09-29</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.185411</td>\n",
       "      <td>1.257964</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>2</td>\n",
       "      <td>2.981538e+08</td>\n",
       "      <td>2.507790e+08</td>\n",
       "      <td>2014-09-02</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.209608</td>\n",
       "      <td>1.172248</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>9</td>\n",
       "      <td>3.432566e+08</td>\n",
       "      <td>2.799395e+08</td>\n",
       "      <td>2014-09-09</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.209608</td>\n",
       "      <td>1.172248</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>16</td>\n",
       "      <td>3.778032e+08</td>\n",
       "      <td>3.584768e+08</td>\n",
       "      <td>2014-09-16</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.209608</td>\n",
       "      <td>1.172248</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>23</td>\n",
       "      <td>2.743273e+08</td>\n",
       "      <td>3.012125e+08</td>\n",
       "      <td>2014-09-23</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.209608</td>\n",
       "      <td>1.172248</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>30</td>\n",
       "      <td>2.875595e+08</td>\n",
       "      <td>3.369596e+08</td>\n",
       "      <td>2014-09-30</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.209608</td>\n",
       "      <td>1.172248</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>3</td>\n",
       "      <td>3.360825e+08</td>\n",
       "      <td>3.401504e+08</td>\n",
       "      <td>2014-09-03</td>\n",
       "      <td>2.0</td>\n",
       "      <td>1.163752</td>\n",
       "      <td>1.157944</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>10</td>\n",
       "      <td>3.867549e+08</td>\n",
       "      <td>2.972462e+08</td>\n",
       "      <td>2014-09-10</td>\n",
       "      <td>2.0</td>\n",
       "      <td>1.163752</td>\n",
       "      <td>1.157944</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>17</td>\n",
       "      <td>2.878720e+08</td>\n",
       "      <td>3.423040e+08</td>\n",
       "      <td>2014-09-17</td>\n",
       "      <td>2.0</td>\n",
       "      <td>1.163752</td>\n",
       "      <td>1.157944</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>24</td>\n",
       "      <td>2.701369e+08</td>\n",
       "      <td>3.407229e+08</td>\n",
       "      <td>2014-09-24</td>\n",
       "      <td>2.0</td>\n",
       "      <td>1.163752</td>\n",
       "      <td>1.157944</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>4</td>\n",
       "      <td>3.492969e+08</td>\n",
       "      <td>2.869627e+08</td>\n",
       "      <td>2014-09-04</td>\n",
       "      <td>3.0</td>\n",
       "      <td>1.139503</td>\n",
       "      <td>1.026762</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>11</td>\n",
       "      <td>3.166415e+08</td>\n",
       "      <td>2.993030e+08</td>\n",
       "      <td>2014-09-11</td>\n",
       "      <td>3.0</td>\n",
       "      <td>1.139503</td>\n",
       "      <td>1.026762</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>18</td>\n",
       "      <td>3.098768e+08</td>\n",
       "      <td>2.745442e+08</td>\n",
       "      <td>2014-09-18</td>\n",
       "      <td>3.0</td>\n",
       "      <td>1.139503</td>\n",
       "      <td>1.026762</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>25</td>\n",
       "      <td>2.686391e+08</td>\n",
       "      <td>3.096380e+08</td>\n",
       "      <td>2014-09-25</td>\n",
       "      <td>3.0</td>\n",
       "      <td>1.139503</td>\n",
       "      <td>1.026762</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>5</td>\n",
       "      <td>2.958247e+08</td>\n",
       "      <td>2.514977e+08</td>\n",
       "      <td>2014-09-05</td>\n",
       "      <td>4.0</td>\n",
       "      <td>0.902682</td>\n",
       "      <td>0.975445</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>12</td>\n",
       "      <td>2.472895e+08</td>\n",
       "      <td>2.510959e+08</td>\n",
       "      <td>2014-09-12</td>\n",
       "      <td>4.0</td>\n",
       "      <td>0.902682</td>\n",
       "      <td>0.975445</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>19</td>\n",
       "      <td>2.553745e+08</td>\n",
       "      <td>2.569703e+08</td>\n",
       "      <td>2014-09-19</td>\n",
       "      <td>4.0</td>\n",
       "      <td>0.902682</td>\n",
       "      <td>0.975445</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>26</td>\n",
       "      <td>2.253898e+08</td>\n",
       "      <td>3.070802e+08</td>\n",
       "      <td>2014-09-26</td>\n",
       "      <td>4.0</td>\n",
       "      <td>0.902682</td>\n",
       "      <td>0.975445</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>6</td>\n",
       "      <td>2.273095e+08</td>\n",
       "      <td>1.768153e+08</td>\n",
       "      <td>2014-09-06</td>\n",
       "      <td>5.0</td>\n",
       "      <td>0.709237</td>\n",
       "      <td>0.669791</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>13</td>\n",
       "      <td>1.879924e+08</td>\n",
       "      <td>1.968713e+08</td>\n",
       "      <td>2014-09-13</td>\n",
       "      <td>5.0</td>\n",
       "      <td>0.709237</td>\n",
       "      <td>0.669791</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>20</td>\n",
       "      <td>2.206844e+08</td>\n",
       "      <td>1.701213e+08</td>\n",
       "      <td>2014-09-20</td>\n",
       "      <td>5.0</td>\n",
       "      <td>0.709237</td>\n",
       "      <td>0.669791</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>27</td>\n",
       "      <td>1.806782e+08</td>\n",
       "      <td>2.283780e+08</td>\n",
       "      <td>2014-09-27</td>\n",
       "      <td>5.0</td>\n",
       "      <td>0.709237</td>\n",
       "      <td>0.669791</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>7</td>\n",
       "      <td>2.020493e+08</td>\n",
       "      <td>1.781561e+08</td>\n",
       "      <td>2014-09-07</td>\n",
       "      <td>6.0</td>\n",
       "      <td>0.712065</td>\n",
       "      <td>0.761712</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>14</td>\n",
       "      <td>1.929401e+08</td>\n",
       "      <td>2.213535e+08</td>\n",
       "      <td>2014-09-14</td>\n",
       "      <td>6.0</td>\n",
       "      <td>0.712065</td>\n",
       "      <td>0.761712</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>21</td>\n",
       "      <td>2.005183e+08</td>\n",
       "      <td>2.113855e+08</td>\n",
       "      <td>2014-09-21</td>\n",
       "      <td>6.0</td>\n",
       "      <td>0.712065</td>\n",
       "      <td>0.761712</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>28</td>\n",
       "      <td>1.896649e+08</td>\n",
       "      <td>2.596058e+08</td>\n",
       "      <td>2014-09-28</td>\n",
       "      <td>6.0</td>\n",
       "      <td>0.712065</td>\n",
       "      <td>0.761712</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    day  total_purchase_amt  total_redeem_amt report_date  weekday  \\\n",
       "0     1        3.819439e+08      2.938111e+08  2014-09-01      0.0   \n",
       "1     8        3.426474e+08      3.097775e+08  2014-09-08      0.0   \n",
       "2    15        3.472844e+08      2.881076e+08  2014-09-15      0.0   \n",
       "3    22        2.853115e+08      3.269821e+08  2014-09-22      0.0   \n",
       "4    29        2.868163e+08      3.368237e+08  2014-09-29      0.0   \n",
       "5     2        2.981538e+08      2.507790e+08  2014-09-02      1.0   \n",
       "6     9        3.432566e+08      2.799395e+08  2014-09-09      1.0   \n",
       "7    16        3.778032e+08      3.584768e+08  2014-09-16      1.0   \n",
       "8    23        2.743273e+08      3.012125e+08  2014-09-23      1.0   \n",
       "9    30        2.875595e+08      3.369596e+08  2014-09-30      1.0   \n",
       "10    3        3.360825e+08      3.401504e+08  2014-09-03      2.0   \n",
       "11   10        3.867549e+08      2.972462e+08  2014-09-10      2.0   \n",
       "12   17        2.878720e+08      3.423040e+08  2014-09-17      2.0   \n",
       "13   24        2.701369e+08      3.407229e+08  2014-09-24      2.0   \n",
       "14    4        3.492969e+08      2.869627e+08  2014-09-04      3.0   \n",
       "15   11        3.166415e+08      2.993030e+08  2014-09-11      3.0   \n",
       "16   18        3.098768e+08      2.745442e+08  2014-09-18      3.0   \n",
       "17   25        2.686391e+08      3.096380e+08  2014-09-25      3.0   \n",
       "18    5        2.958247e+08      2.514977e+08  2014-09-05      4.0   \n",
       "19   12        2.472895e+08      2.510959e+08  2014-09-12      4.0   \n",
       "20   19        2.553745e+08      2.569703e+08  2014-09-19      4.0   \n",
       "21   26        2.253898e+08      3.070802e+08  2014-09-26      4.0   \n",
       "22    6        2.273095e+08      1.768153e+08  2014-09-06      5.0   \n",
       "23   13        1.879924e+08      1.968713e+08  2014-09-13      5.0   \n",
       "24   20        2.206844e+08      1.701213e+08  2014-09-20      5.0   \n",
       "25   27        1.806782e+08      2.283780e+08  2014-09-27      5.0   \n",
       "26    7        2.020493e+08      1.781561e+08  2014-09-07      6.0   \n",
       "27   14        1.929401e+08      2.213535e+08  2014-09-14      6.0   \n",
       "28   21        2.005183e+08      2.113855e+08  2014-09-21      6.0   \n",
       "29   28        1.896649e+08      2.596058e+08  2014-09-28      6.0   \n",
       "\n",
       "    purchase_weekday  redeem_weekday  \n",
       "0           1.185411        1.257964  \n",
       "1           1.185411        1.257964  \n",
       "2           1.185411        1.257964  \n",
       "3           1.185411        1.257964  \n",
       "4           1.185411        1.257964  \n",
       "5           1.209608        1.172248  \n",
       "6           1.209608        1.172248  \n",
       "7           1.209608        1.172248  \n",
       "8           1.209608        1.172248  \n",
       "9           1.209608        1.172248  \n",
       "10          1.163752        1.157944  \n",
       "11          1.163752        1.157944  \n",
       "12          1.163752        1.157944  \n",
       "13          1.163752        1.157944  \n",
       "14          1.139503        1.026762  \n",
       "15          1.139503        1.026762  \n",
       "16          1.139503        1.026762  \n",
       "17          1.139503        1.026762  \n",
       "18          0.902682        0.975445  \n",
       "19          0.902682        0.975445  \n",
       "20          0.902682        0.975445  \n",
       "21          0.902682        0.975445  \n",
       "22          0.709237        0.669791  \n",
       "23          0.709237        0.669791  \n",
       "24          0.709237        0.669791  \n",
       "25          0.709237        0.669791  \n",
       "26          0.712065        0.761712  \n",
       "27          0.712065        0.761712  \n",
       "28          0.712065        0.761712  \n",
       "29          0.712065        0.761712  "
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "day_pred['total_purchase_amt'] *= day_pred['purchase_weekday']\n",
    "day_pred['total_redeem_amt'] *= day_pred['redeem_weekday']\n",
    "day_pred"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>report_date</th>\n",
       "      <th>total_purchase_amt</th>\n",
       "      <th>total_redeem_amt</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2014-09-01</td>\n",
       "      <td>3.819439e+08</td>\n",
       "      <td>2.938111e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>2014-09-02</td>\n",
       "      <td>2.981538e+08</td>\n",
       "      <td>2.507790e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>2014-09-03</td>\n",
       "      <td>3.360825e+08</td>\n",
       "      <td>3.401504e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>2014-09-04</td>\n",
       "      <td>3.492969e+08</td>\n",
       "      <td>2.869627e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>2014-09-05</td>\n",
       "      <td>2.958247e+08</td>\n",
       "      <td>2.514977e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>2014-09-06</td>\n",
       "      <td>2.273095e+08</td>\n",
       "      <td>1.768153e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>2014-09-07</td>\n",
       "      <td>2.020493e+08</td>\n",
       "      <td>1.781561e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2014-09-08</td>\n",
       "      <td>3.426474e+08</td>\n",
       "      <td>3.097775e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>2014-09-09</td>\n",
       "      <td>3.432566e+08</td>\n",
       "      <td>2.799395e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>2014-09-10</td>\n",
       "      <td>3.867549e+08</td>\n",
       "      <td>2.972462e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>2014-09-11</td>\n",
       "      <td>3.166415e+08</td>\n",
       "      <td>2.993030e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>2014-09-12</td>\n",
       "      <td>2.472895e+08</td>\n",
       "      <td>2.510959e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>2014-09-13</td>\n",
       "      <td>1.879924e+08</td>\n",
       "      <td>1.968713e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>2014-09-14</td>\n",
       "      <td>1.929401e+08</td>\n",
       "      <td>2.213535e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2014-09-15</td>\n",
       "      <td>3.472844e+08</td>\n",
       "      <td>2.881076e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>2014-09-16</td>\n",
       "      <td>3.778032e+08</td>\n",
       "      <td>3.584768e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>2014-09-17</td>\n",
       "      <td>2.878720e+08</td>\n",
       "      <td>3.423040e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>2014-09-18</td>\n",
       "      <td>3.098768e+08</td>\n",
       "      <td>2.745442e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>2014-09-19</td>\n",
       "      <td>2.553745e+08</td>\n",
       "      <td>2.569703e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>2014-09-20</td>\n",
       "      <td>2.206844e+08</td>\n",
       "      <td>1.701213e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>2014-09-21</td>\n",
       "      <td>2.005183e+08</td>\n",
       "      <td>2.113855e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2014-09-22</td>\n",
       "      <td>2.853115e+08</td>\n",
       "      <td>3.269821e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>2014-09-23</td>\n",
       "      <td>2.743273e+08</td>\n",
       "      <td>3.012125e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>2014-09-24</td>\n",
       "      <td>2.701369e+08</td>\n",
       "      <td>3.407229e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>2014-09-25</td>\n",
       "      <td>2.686391e+08</td>\n",
       "      <td>3.096380e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>2014-09-26</td>\n",
       "      <td>2.253898e+08</td>\n",
       "      <td>3.070802e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>2014-09-27</td>\n",
       "      <td>1.806782e+08</td>\n",
       "      <td>2.283780e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>2014-09-28</td>\n",
       "      <td>1.896649e+08</td>\n",
       "      <td>2.596058e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2014-09-29</td>\n",
       "      <td>2.868163e+08</td>\n",
       "      <td>3.368237e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>2014-09-30</td>\n",
       "      <td>2.875595e+08</td>\n",
       "      <td>3.369596e+08</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   report_date  total_purchase_amt  total_redeem_amt\n",
       "0   2014-09-01        3.819439e+08      2.938111e+08\n",
       "5   2014-09-02        2.981538e+08      2.507790e+08\n",
       "10  2014-09-03        3.360825e+08      3.401504e+08\n",
       "14  2014-09-04        3.492969e+08      2.869627e+08\n",
       "18  2014-09-05        2.958247e+08      2.514977e+08\n",
       "22  2014-09-06        2.273095e+08      1.768153e+08\n",
       "26  2014-09-07        2.020493e+08      1.781561e+08\n",
       "1   2014-09-08        3.426474e+08      3.097775e+08\n",
       "6   2014-09-09        3.432566e+08      2.799395e+08\n",
       "11  2014-09-10        3.867549e+08      2.972462e+08\n",
       "15  2014-09-11        3.166415e+08      2.993030e+08\n",
       "19  2014-09-12        2.472895e+08      2.510959e+08\n",
       "23  2014-09-13        1.879924e+08      1.968713e+08\n",
       "27  2014-09-14        1.929401e+08      2.213535e+08\n",
       "2   2014-09-15        3.472844e+08      2.881076e+08\n",
       "7   2014-09-16        3.778032e+08      3.584768e+08\n",
       "12  2014-09-17        2.878720e+08      3.423040e+08\n",
       "16  2014-09-18        3.098768e+08      2.745442e+08\n",
       "20  2014-09-19        2.553745e+08      2.569703e+08\n",
       "24  2014-09-20        2.206844e+08      1.701213e+08\n",
       "28  2014-09-21        2.005183e+08      2.113855e+08\n",
       "3   2014-09-22        2.853115e+08      3.269821e+08\n",
       "8   2014-09-23        2.743273e+08      3.012125e+08\n",
       "13  2014-09-24        2.701369e+08      3.407229e+08\n",
       "17  2014-09-25        2.686391e+08      3.096380e+08\n",
       "21  2014-09-26        2.253898e+08      3.070802e+08\n",
       "25  2014-09-27        1.806782e+08      2.283780e+08\n",
       "29  2014-09-28        1.896649e+08      2.596058e+08\n",
       "4   2014-09-29        2.868163e+08      3.368237e+08\n",
       "9   2014-09-30        2.875595e+08      3.369596e+08"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "day_pred = day_pred.sort_values('report_date')[['report_date','total_purchase_amt','total_redeem_amt']]\n",
    "day_pred"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>report_date</th>\n",
       "      <th>total_purchase_amt</th>\n",
       "      <th>total_redeem_amt</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>20140901</td>\n",
       "      <td>3.819439e+08</td>\n",
       "      <td>2.938111e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>20140902</td>\n",
       "      <td>2.981538e+08</td>\n",
       "      <td>2.507790e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>20140903</td>\n",
       "      <td>3.360825e+08</td>\n",
       "      <td>3.401504e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>20140904</td>\n",
       "      <td>3.492969e+08</td>\n",
       "      <td>2.869627e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>20140905</td>\n",
       "      <td>2.958247e+08</td>\n",
       "      <td>2.514977e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>20140906</td>\n",
       "      <td>2.273095e+08</td>\n",
       "      <td>1.768153e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>20140907</td>\n",
       "      <td>2.020493e+08</td>\n",
       "      <td>1.781561e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>20140908</td>\n",
       "      <td>3.426474e+08</td>\n",
       "      <td>3.097775e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>20140909</td>\n",
       "      <td>3.432566e+08</td>\n",
       "      <td>2.799395e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>20140910</td>\n",
       "      <td>3.867549e+08</td>\n",
       "      <td>2.972462e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>20140911</td>\n",
       "      <td>3.166415e+08</td>\n",
       "      <td>2.993030e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>20140912</td>\n",
       "      <td>2.472895e+08</td>\n",
       "      <td>2.510959e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>20140913</td>\n",
       "      <td>1.879924e+08</td>\n",
       "      <td>1.968713e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>20140914</td>\n",
       "      <td>1.929401e+08</td>\n",
       "      <td>2.213535e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>20140915</td>\n",
       "      <td>3.472844e+08</td>\n",
       "      <td>2.881076e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>20140916</td>\n",
       "      <td>3.778032e+08</td>\n",
       "      <td>3.584768e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>20140917</td>\n",
       "      <td>2.878720e+08</td>\n",
       "      <td>3.423040e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>20140918</td>\n",
       "      <td>3.098768e+08</td>\n",
       "      <td>2.745442e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>20140919</td>\n",
       "      <td>2.553745e+08</td>\n",
       "      <td>2.569703e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>20140920</td>\n",
       "      <td>2.206844e+08</td>\n",
       "      <td>1.701213e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>20140921</td>\n",
       "      <td>2.005183e+08</td>\n",
       "      <td>2.113855e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>20140922</td>\n",
       "      <td>2.853115e+08</td>\n",
       "      <td>3.269821e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>20140923</td>\n",
       "      <td>2.743273e+08</td>\n",
       "      <td>3.012125e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>20140924</td>\n",
       "      <td>2.701369e+08</td>\n",
       "      <td>3.407229e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>20140925</td>\n",
       "      <td>2.686391e+08</td>\n",
       "      <td>3.096380e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>20140926</td>\n",
       "      <td>2.253898e+08</td>\n",
       "      <td>3.070802e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>20140927</td>\n",
       "      <td>1.806782e+08</td>\n",
       "      <td>2.283780e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>20140928</td>\n",
       "      <td>1.896649e+08</td>\n",
       "      <td>2.596058e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>20140929</td>\n",
       "      <td>2.868163e+08</td>\n",
       "      <td>3.368237e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>20140930</td>\n",
       "      <td>2.875595e+08</td>\n",
       "      <td>3.369596e+08</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   report_date  total_purchase_amt  total_redeem_amt\n",
       "0     20140901        3.819439e+08      2.938111e+08\n",
       "5     20140902        2.981538e+08      2.507790e+08\n",
       "10    20140903        3.360825e+08      3.401504e+08\n",
       "14    20140904        3.492969e+08      2.869627e+08\n",
       "18    20140905        2.958247e+08      2.514977e+08\n",
       "22    20140906        2.273095e+08      1.768153e+08\n",
       "26    20140907        2.020493e+08      1.781561e+08\n",
       "1     20140908        3.426474e+08      3.097775e+08\n",
       "6     20140909        3.432566e+08      2.799395e+08\n",
       "11    20140910        3.867549e+08      2.972462e+08\n",
       "15    20140911        3.166415e+08      2.993030e+08\n",
       "19    20140912        2.472895e+08      2.510959e+08\n",
       "23    20140913        1.879924e+08      1.968713e+08\n",
       "27    20140914        1.929401e+08      2.213535e+08\n",
       "2     20140915        3.472844e+08      2.881076e+08\n",
       "7     20140916        3.778032e+08      3.584768e+08\n",
       "12    20140917        2.878720e+08      3.423040e+08\n",
       "16    20140918        3.098768e+08      2.745442e+08\n",
       "20    20140919        2.553745e+08      2.569703e+08\n",
       "24    20140920        2.206844e+08      1.701213e+08\n",
       "28    20140921        2.005183e+08      2.113855e+08\n",
       "3     20140922        2.853115e+08      3.269821e+08\n",
       "8     20140923        2.743273e+08      3.012125e+08\n",
       "13    20140924        2.701369e+08      3.407229e+08\n",
       "17    20140925        2.686391e+08      3.096380e+08\n",
       "21    20140926        2.253898e+08      3.070802e+08\n",
       "25    20140927        1.806782e+08      2.283780e+08\n",
       "29    20140928        1.896649e+08      2.596058e+08\n",
       "4     20140929        2.868163e+08      3.368237e+08\n",
       "9     20140930        2.875595e+08      3.369596e+08"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "day_pred['report_date'] = day_pred['report_date'].apply(lambda x: str(x).replace('-','')[0:8])\n",
    "day_pred"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [],
   "source": [
    "day_pred.to_csv('rule_base_0301.csv', index=False, header=None)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3.8.0 64-bit",
   "language": "python",
   "name": "python38064bit112f637fd6ff46b68be3936af779d5ac"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.0"
  },
  "widgets": {
   "application/vnd.jupyter.widget-state+json": {
    "state": {},
    "version_major": 2,
    "version_minor": 0
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
